Versions Compared

Key

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

...

Tests should have names that clearly indicate the behavior being tested. For instance, catalogReturnsMetacardIdWhenIngestSucceeds or exceptionThrownWhenInvalidUserNameProvided.

Test Positive and Negative

...

Scenarios

Always remember to tests all positive and negative test scenarios and ensure that the proper results (error code, exception, message, etc.) are returned.

Warning

Some error scenarios are extremely difficult to test using end-to-end or component tests, which makes testing all exception scenarios at the unit test level even more critical.

Use Proper Assertions and Validations

When writing a test, always:

...

This is especially important in unit tests as these may be the only tests where some of those exception scenarios can be tested.

...

Clean Up

...

After Yourself

Always make sure that tests clean up after themselves to ensure that a test failure doesn't impact other tests.

...

When dealing with legacy code that would be difficult to unit test, consider writing component tests instead. Those should be easier to write while still making it safe to refactor or change the code as needed.

Info

Refactorings automatically performed by an IDE are usually safe and may not require adding tests first. This is especially true for simple structural refactorings that do not affect the logic of the code such as extract class, extract method, etc. If such refactorings make writing the tests easier, then applying them without existing tests can be considered.

Smells

Tests Difficult to Name

...