...
Best Practices
Be Test-Driven
Come Follow the Test-Driven Development Test Cycle.
First, come up with a 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 . For or issue has been fixed.
Then for each one:
...
- Add a test
- Run
...
- all tests and see if the new test fails
- Write the code
- Run the
...
- tests until they pass
- Refactor the code as needed
- Move on to the next test
...
Be Behavior-Driven
Test behaviors, not methods or lines of code.
...
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.
Warning |
---|
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. |
Assertions and Validations
When writing a test, always:
- Assert that the expected value is returned
- Assert that the object under test is in the expected state
- Verify that all the mocked dependencies were called
- Verify that all the mocked dependencies were called with the right parameters
Mock Dependencies
Use Proper Clean Up Mechanisms
Smells
Tests Difficult to Name
...