testing is a testing methodology where the objective is to test the application as a whole.
E2E tests in TEAMMATES can be found in the package teammates.e2e
.
TEAMMATES E2E testing requires Firefox, Chrome, or Edge (Chromium-based).
Before running tests, modify src/e2e/resources/test.properties
if necessary, e.g. to configure which browser and test accounts to use.
E2E tests follow this configuration:
Test suite | Command | Results can be viewed in |
---|---|---|
E2E tests | ./gradlew e2eTests | {project folder}/build/reports/e2e-test-try-{n}/index.html , where {n} is the sequence number of the test run |
Any individual E2E test | ./gradlew e2eTestTry1 --tests TestClassName | {project folder}/build/reports/e2e-test-try-1/index.html |
E2E tests
will be run in their entirety once and the failed tests will be re-run a few times.E2E tests
, it is important to have the dev server running locally first if you are testing against it.If you are testing against a production server (staging server or live server), some additional tasks need to be done.
Edit src/e2e/resources/test.properties
as instructed is in its comments.
If you are testing email sending, you need to setup a Gmail API
as follows:
src/e2e/resources/gmail-api
(create the gmail-api
folder) of your project and rename it to client_secret.json
.EmailAccountTest
to confirm that the setup works. For the first run, it is expected that you will need to grant access from the test Gmail account to the above API.Run the full test suite or any subset of it as how you would have done it in dev server.
As E2E tests should be written from the end user perspective, each test case should reflect some user workflow.
In TEAMMATES, E2E test cases are organized by page. For each page, we:
Selenium is used to locate and interact with elements in the UI.
All E2E test classes inherit from BaseE2ETestCase
which contains methods that are common to most test cases, such as preparing the Browser
object used for testing.
To help verify the state of the database, BackDoor
contains methods to create API calls to the back-end without going through the UI.
In order to make E2E testing more robust to UI changes, the Page Object Pattern is adopted.
Each page in TEAMMATES is represented by a page object class. The page object class abstracts interactions with UI elements and only exposes the functionality of each page as methods.
To maximise the effectiveness of Page Object Pattern, interaction with UI elements should not occur outside the page objects.
The page object should have methods to represent the main functionality of the page that testers can use to simulate user actions.
fillSearchBox
and clickSearchButton
, it is better to have a method searchForInstructor
which hides the UI elements used.All Page Object classes inherit from AppPage
which contains methods that are common for interacting with the web elements such as filling in textboxes.
Why are all the tests done in one testAll()
method?
We bundle together everything as one test case instead of having multiple test cases. The advantage is that the time for the whole test class will be reduced because we minimize repetitive per-method setup/teardown. The downside is that it increases the time spent on re-running failed tests as the whole class has to be re-run. We opt for this approach because we expect tests to pass more frequently than to fail.
Why is there one JSON file for each test case?
Each test case has its own JSON file and the data inside has a unique prefix to prevent clashes in the database that may cause test failure, since tests are run concurrently.