Versions Compared

Key

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

...

  • Don't use sleep(), since it often leads to brittle tests.  If you find that you have to wait for an event or wait for some work to be done by another thread, prefer latches or thread notifications to sleeps.
  • Try to keep individual tests small, and only test one thing per test.
  • Use mocking when you need to include a complicated service to satisfy dependencies.
  • Maven may choose to run multiple tests in the same Java virtual machine.  If you use static variables in classes, be sure to reset them to known starting values before each test runs.
  • Do not use local resources like files and IP Addresses in tests.

If you add a class, consider adding the following basic tests for it first:

  • Any class that defines equals(), hashCode(), or toString() must test these methods.  The Google Guava EqualsTester class provides full coverage for these methods:

    final FlowId flowId1 = FlowId.valueOf(1);
    final FlowId sameAsFlowId1 = FlowId.valueOf(1);
    final FlowId flowId2 = FlowId.valueOf(2);

    /**
    * Checks the operation of equals(), hashCode and toString() methods.
    */
    @Test
    public void testEquals() {
    new EqualsTester()
    .addEqualityGroup(flowId1, sameAsFlowId1)
    .addEqualityGroup(flowId2)
    .testEquals();
    }

     

     

We use the Hamcrest matchers, version 1.3.