RSpec (or Jasmine/Mocha) style tests for native Java 8, a bit like the following:
@RunWith(JarSpecJUnitRunner.class)
public class MinimalSpec implements Specification {
@Override
public SpecificationNode root() {
return describe("This specification",
it("contains a statement with a test", () -> assertTrue(true))
);
}
}
Allows for more expressive test names without very_long_underscore_ridden_test_method_names, and for more flexible test structure. Java 8 features such as lambda expressions make this possible with less boilerplate. See wiki/Motivation for more.
-
Add JarSpec to your project dependencies. See below for Maven and the dependency info page for other build tools.
-
Start writing specs! See wiki/Implementing Specifications for more details, or the project's own tests for examples.
Add the dependency to your pom:
<dependencies>
....
<dependency>
<groupId>io.hgc</groupId>
<artifactId>jarspec</artifactId>
<version>2.0.0</version>
<scope>test</scope>
</dependency>
....
</dependencies>
Configure SureFire to pick up classes named *Spec
(although you can stick with the default *Test
convention if you prefer):
<build>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<includes>
<include>**/*Spec.java</include>
</includes>
</configuration>
</plugin>
...
</plugins>
</build>
The current release on Maven Central is stable. See open milestones for further planned features. Releases numbers follow the Semantic Versioning specification for backwards compatibility.