This project shows how Xtend's Active Annotations can be used to enhance tooling for a specific framework. It solves most of the things that I did not like about Junit 4. Most of these issues will be fixed in the new Junit Lambda project, so I won't put much more work into this one.
See the examples or read on for more details.
This annotation automates common JUnit patterns. It also adds compile-time validation and convenience methods for more readable tests.
- a method is automatically annotated with
@Testif it is
- not annotated with
- Test methods are automatically
- a compile error is raised if a test method declares parameters
org.junit.Assert.*is statically imported
- you can use
x => 3instead of
- expected exceptions can be declared using a lambda expression like
- fields annotated with
@Ruleare automatically public
- a compile error is raised if a
@Rulehas any other visibility or is declared static
- fields/methods annotated with
@DataPointare automatically public und static
- if a test is annotated with
@Theory, the test class will get the
- if there are
org.junit.Assume.*is statically imported
@Theoryparameters are flagged with an error if there are not matching
- you can use
"Foo" => startsWith("F")instead of
org.hamcrest.Matchersis statically imported, depending on which is on the classpath
- an ErrorCollector is added as an extension field, so you can softly assert using
Collects all tests in a package (and optionally all subpackages) and creates a Suite from them. Especially useful if you want to group your tests using Categories instead of writing @SuiteClasses manually. This is basically like using ClassPathSuite, but statically generated, so you will have quick test startup times.