Skip to main content

Best Practices

note

Make sure you've gone through What to test, Prepare yourself and many chapters from Guide before going ahead.

We've documented few important best practices to help you with e2e tests:

Write focused test cases#

Your test cases shouldn't be responsible for verifying more than a single and focused functionality. For example, in a note taking app's 'listing and filtering notes' module, one of the test case could be 'pressing next loads next batch of notes'. In that test we can perform following steps:

  • Open the 'notes listing' page. When notes are loaded, keep the id of the last note in variable lastNoteId.
  • Hit 'Next' and verify that the first note from next batch of notes has id > lastNoteId.

No more verification in this particular test. This way test cases look focused, to the point, easily manageable and follow good coding practices.

No two tests share state#

Every test case should be able to successfully run on it's own with no dependence on any other test. No test should share test state with other test. For instance, if you've set a custom timeout in some test, don't forget to reset it in the same test. Don't leave it on other tests to first reset any custom timeouts. Another example, if you open a url and do some tests on a page, don't expect another test to resume the testing because there is no defined order in which multiple tests run in a build. Write focused test and finish a particular test case within it's own single test.