How to Selenium test Django project that retrieves data through APIs? - django

I have a Django Project. I want to make end-to-end tests for it using Selenium.
It interacts with Other components (usually run through docker-compose) API and functions properly.
The Django Project and 'Other Components' are different repositories (obviously there are multiple 'other components')
Testing of parts that don't involve API calls, have been tested.

You can use a continuous integration like Jenkins to do your automated task like Selenium.
It's really easy to install localy and/or to serve.
How to install Jenkins : here
have a great day!

Related

What are the best practices for testing a FastAPI project with JWT authentication?

I have FastAPI project which does the following:
Register users(unauthenticated)
CRUD operations on user resources(authenticated)
What I want to do:
Develop an automated testing framework to unit test all the APIs
Run that on a devops platform like jenkins regularly
Run it locally before deployment
Some specific doubts I have:
For testing, should I use the OpenAPI generated client sdk or the FastAPI client or use the python requests module?
Authentication should happen only once and reuse the JWT token or fresh authentication for each API test ?
Should I use the same pydantic modules for dev and testing or re-write them to ensure that no issues were introduced in case of updated models ?
How to do proper unit testing when one API requires result from multiple other APIs?
Use the built-in TestClient
Use a fixture and let pytest sort it out for you; if it's too slow to reauthenticate each time, change the scope of the fixture to a larger scope (i.e. class, module, session, etc.). You can also use FastAPI's dependency_overrides to let your tests run with static authentication configured (so that you can skip actually authenticating in most of your tests).
You should test what you use in your application. Nothing specific written for your tests, except if necessary to make your application testable in a better way.
The only "proper" thing is that your API has been tested to work as you expect it to work. Do multiple API calls if necessary, but move them into fixtures to get composable sets of dependencies for tests (i.e. the result of the fixture can be cached and re-used for all tests in a test class if necessary). If you have tests that depend on a customer being created, create a fixture that creates a customer and use that fixture in the tests where a created customer is necessary.

Testing and verifying an Angular2+ build

I am having an Angular2+ application.
I have done some unit testing with Karma-Jasmine. But my assumption is that this is only for dev enviroment(pre production).
I am looking for a testing framework through which the "dist" folder build can be verified(components, web services, etc...)? so that once the build is taken, some script that do login, should able to verify the response object for login service etc...
Sounds like you are asking how to do end-to-end testing to your application in addition to unit tests. In that case Selenium and more modern Cypress are what you are looking for.

Do I need a unit-testing framework if I'm already using Cypress in a Vue.js app?

When scaffolding a new project with the Vue.js CLI, it offers a choice of both unit-testing and E2E-testing frameworks.
Unit-testing functionality is perfectly adequate in Cypress. My question, then: is there an advantage to using a distinct unit-testing framework if I'm already using Cypress?
There is a third-party adapter made by a Cypress contributor here called cypress-vue-unit-test(along with unit-test adapters for other popular frameworks).
You should check that out and see if it meets your needs over, say, Jest
From this tutorial about unit testing vuejs, some Jest advantages over Cypress are:
Built in code coverage
Snapshot testing
Module mocking utilities
Also see repo for vue-test-utils

Testing gmail addon

I've created a gmail addon which uses oauth to make external api calls using UrlFetchApp and then uses cards with CardService to show some info.
It all works but there's no documentation on the gmail addon page about how to test the addon. My goal is to write some unit and integration test for my addon core working and have it run on ci services such as Travis. There are many classes the addon uses which are only available in the app script environment such as CardService, OAuth2, GmailApp so mocking all of their functions is quite a bit of work.
Has anybody developed gmail addon with tests which can run on ci services?
GMail add-ons are relatively new to the GSuite ecosystem so you're unlikely to find mocks for it. However, there have been attempts to build Test frameworks for Apps Script.
There is an "awesome list" of GAS resources maintained by Alexander Ivanov on Github with a section dedicated to testing. See link below:
https://github.com/oshliaer/google-apps-script-awesome-list#testing
In its current state it may be difficult to set up Apps Script for continuous integration but with the planned language upgrade to Chrome's V8 engine that may soon change.

TestNG unit test at maven install, install ->deploy to jetty ->start jetty ->run test -> stop server

I have a maven project.
I want to test (spring) controller class and also wrote a test class.To successfully run this test class,I want the web app to be deployed in the (jetty )server.
How I can achieve this, when I execute maven clean install.project is
built->deployed to server->start server->run test->stop server
I have been looking at jetty plugin and cargo plugin but still finding it difficult to do what I want.
If you want to unit test your spring controllers, you do not need to have your web application deployed to jetty. Spring framework has testing support as documented here.
There are many examples in the web. You can also refer to the test classes here which uses testNG.
If you do want to run tests in jetty, then refer to these instructions. Essentially you would bind the jetty start and stop to pre-integration-test and post-integration-test phases.