juniter
Framework that extends JUnit functionality. Adds alternative approach for test rules, automatic mocking, context creation in guice and reflection assert utilities. The project juniter uses semantic versioning and tagging to provide clean version numbers.
Test life cycle
Test life cycle org.eluder.juniter.core.TestLifeCycle
provides the hooks to different phases of a unit test. The main reason for custom interface over the JUnit org.junit.rules.TestRule
interface is that the test rules do not allow access to the test instance.
Comparison between the TestLifeCycle and TestRule interfaces:
TestLifeCycle | TestRule | |
Easy access to test instance | yes | no |
Easy access to test class | yes | yes |
Easy access to test method | yes | no |
Must reset its own state after each test | no | yes |
Requires a custom JUnit runner | yes | no |
Usage
Core module requires the following dependency:
<dependency>
<groupId>org.eluder.juniter</groupId>
<artifactId>juniter-core</artifactId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
Using test life cycles requires defining the juniter test runner and defining the life cycles to use:
@RunWith(TestRunner.class)
@TestLifeCycles({ FirstLifeCycle.class, SecondLifeCycle.class })
public class MyTest {
...
}
Automatic mocking can be achieved with the shorthand mock runner or defining the mock life cycle as one test life cycle:
@RunWith(MockTestRunner.class)
public class MockTest {
...
}
is equivalent to
@RunWith(TestRunner.class)
@TestLifeCycles({ MockLifeCycle.class })
public class MockTest {
...
}
Guice integration requires the following dependency:
<dependency>
<groupId>org.eluder.juniter</groupId>
<artifactId>juniter-guice</artifactId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
Continuous integration
Travis CI builds juniter with Oracle JDK 7 and OpenJDK 6.
License
The project juniter is licensed under the MIT license.