This page covers some common testing best practices and anti-patterns.
Follow the Test-Driven Development Test Cycle.
First, come up with an initial list of end to end, component/service and/or unit tests that will be needed to show that the user story, requirement or improvement works as expected or issue has been fixed.
Then for each one:
Test behaviors, not methods or lines of code.
Write each test following the Behavior-Driven Development structure, i.e., Given/When/Then. In other words make sure each test:
Tests should have names that clearly indicate the behavior being tested. For instance, catalogReturnsMetacardIdWhenIngestSucceeds or errorIsReturnedWhenInvalidUserNameIsProvided.
Always remember to tests all positive and negative test scenarios and ensure that the proper results (error code, exception, message, etc.) are returned and provided in the later case.
Some error scenarios are extremely difficult to test using end-to-end or component/service tests, which makes testing all exception scenarios at the unit test level even more critical. |
When writing a test, always:
Sleeps in tests should be avoided as they open the door to timing issues and race conditions, slow tests down and are a major cause of test flakiness.
Some options to avoid sleeps in tests include: