Unit tests for ONOS are built using the JUnit framework, version 4.11. Unit tests are used to verify correctness of implementations and are run as part of every full build of ONOS. The nightly SonarQube build runs all of the unit tests and produces coverage data that can be seen here.
Unit tests should be as short, fast and reliable as they can be. Every developer on the project will be running your tests, they should be easy to run and produce accurate results. Here are some key ways to write tests that are not brittle:
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.