Versions Compared

Key

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

Distributed Test Recommendations

Note: All examples can be found here.

The goals of the Green Team

...

  • Expected vs unexpected exceptions in tests
  • Never catch unexpected exceptions. That is bad... way bad...
    • Special case: Asynchronous actions may need to catch checked exceptions and use ErrorCollector
  • Use method throws clause for unexpected exceptions 
    • The alternative serves to make failures more opaque. 
    • Fixing test failures (as you will have to do at some point) is all about visibility into the problems of the test. 
  • Use AssertJ catchThrowable or assertThatThrown for expected exceptions
    • Avoid using JUnit expected exception support such as ExpectedException Rule or Test annotation expected element. Example: @Test(expected = Exception.class) 
    • Remember to catch specific exceptions, not whole parent classes. If someone adds an additional exception, will it break your test?

Examples: ErrorHandlingTest ErrorHandlingTest, ExpectedExceptionTest

Sometimes you think they’re helping...

...