Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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:

...

  1. Add a test
  2. Run

...

  1. all tests and see if the new test fails
  2. Write the code
  3. Run the

...

  1. tests until they pass
  2. Refactor the code as needed
  3. 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

...