@Documented @Retention(value=RUNTIME) @Target(value=FIELD) public @interface Rule
This field must be public, final, non static and of type TestRule
.
This annotation can be used only once on a class.
In case one test class extends another one, it is possible to have one field annotated with this annotation per class. The rule of the upper classes are executed around the once of the lower classes.
For example :
@Rule public final TestRule rule = before(this::prepare).around(after(this::clean));This will define that the method
prepare
of the test class will
be execute before each test and then, the method clean
after
each test. Of course, thanks to the lambda, it is not required to reference a
method of this class, but it is also possible to pass some code directly in
line (()->{}
).TestRule
Copyright © 2015 Powerunit. All rights reserved.