|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | ||||||||
@Retention(value=RUNTIME) @Target(value=METHOD) public @interface Prerequisite
Test cases can be dependent of prerequisites, e.g. be online in Internet, have a database available, have database filled with specific test data, etc.
For these cases it can be very annoying to @Ignore the test
cases, because it may be different for each individual run. For this
requirement, the @Prerequisite annotation can be used.
Each test case annotated with @Prerequisite will be checked,
whether the condition is fulfilled. If not, the test case will be marked as
ignored.
For example:
@Prerequisite(requires="isDBAvailable")
@Test public void doDBTest() {
// ...
}
The method called (here: isDBAvailable) must be implemented with
following signature:
public.
boolean or Boolean value.
public boolean isDBAvailable (Description testDescription);. See
Descriptionpublic boolean isDBAvailable (String className, String methodName);public boolean isDBAvailable ();Some examples:
public boolean isNonProductionTest(Description desc) {
// all production tests start with "prod"
return !desc.getDisplayName().startsWith("prod");
}
public boolean isActiveTest(String className, String methodName) {
// for some reason, SpecialBsinessTest.test100() has to be taken out of test suite
if (("SpecialBusinessTest".equals(className)) && ("test100".equals(methodName))) {
return false;
}
return true;
}
public boolean isDBAvailable() {
// we check, whether DB is available
boolean available = ...;
return available;
}
This method can also be provided by a static helper class, when specifiying a
callee attribute to annotation.
For example:
@Prerequisite (requires="isDBAvailable", callee=DBHelper.class)
@Test public void doDBTest() {
...
}
public class DBHelper {
public static boolean isDBAvailable() {
boolean available = ...;
return available;
}
}
TODO: Design question 1: @Prerequisite can also be made an extension
to @Ignore e.g.
@Ignore (values="Check for database available", when="!isDBAvailable")@Ignore. Means, you cannot later
distinguish between @Ignore and @Prerequisite runs.
| Required Element Summary | |
|---|---|
java.lang.String |
requires
Attribute for the method to be called for the prerequsite. |
| Optional Element Summary | |
|---|---|
java.lang.Class<?> |
callee
The class to be called. |
| Element Detail |
|---|
public abstract java.lang.String requires
public abstract java.lang.Class<?> callee
NoCallee means, call
the test class itself.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | ||||||||