My application have several execution modes, and in 1 mode it is normal that some of my tests will throw a concrete exception. I need to annotate this methods with something
What about using JUnit Extensions?
The following example is taken from their Tutorial.
It provides aditional annotations for Prerequisites (@Prerequisite): Ignore tests based on conditions.
The required approach would be to check this during running tests. So you can simply add a @Prerequisite(requires="") annotation.
public class TestFillDatabase {
@Prerequisite(requires = "databaseIsAvailable")
@Test public void fillData() {
// ...
}
public boolean databaseIsAvailable() {
boolean isAvailable = ...;
return isAvailable;
}
}
public class TestFillDatabase {
@Prerequisite(requires = "databaseIsAvailable")
@Test public void fillData() {
// ...
}
public boolean databaseIsAvailable() {
boolean isAvailable = ...;
return isAvailable ;
}
}
This specified methods with @Prerequisite(requires = "databaseIsAvailable") must be a public method, returning a boolean or Boolean value.
If these methods will be consolidated in helper classes, you can also specify static methods within a class to be called using @Prerequisite(requires = "databaseIsAvailable", callee="DBHelper").
public class TestFillDatabase {
@Prerequisite(requires = "databaseIsAvailable", callee="DBHelper")
@Test public void fillData() {
// ...
}
}
public class DBHelper {
public static boolean databaseIsAvailable() {
boolean isAvailable = ...;
return isAvailable ;
}
}