I usually use @Ignore("comment on why it is ignored"). IMO comment is very important for other developers to find out why the test is disabled or for how long (maybe it's just temporary).
EDIT:
By default, ignored tests have only type information Tests run: ... Skipped: 1 .... How to print the value of annotation Ignore?
RunListener:
public class PrintIgnoreRunListener extends RunListener {
@Override
public void testIgnored(Description description) throws Exception {
super.testIgnored(description);
Ignore ignore = description.getAnnotation(Ignore.class);
String ignoreMessage = String.format(
"@Ignore test method '%s()': '%s'",
description.getMethodName(), ignore.value());
System.out.println(ignoreMessage);
}
}
, JUnit RunListener Runner, PrintIgnoreRunListener:
public class MyJUnit4Runner extends BlockJUnit4ClassRunner {
public MyJUnit4Runner(Class<?> clazz) throws InitializationError {
super(clazz);
}
@Override
public void run(RunNotifier notifier) {
notifier.addListener(new PrintIgnoreRunListener());
super.run(notifier);
}
}
- :
@RunWith(MyJUnit4Runner.class)
public class MyTestClass {
}
maven surefire, Runner, surefire :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<configuration>
<properties>
<property>
<name>listener</name>
<value>com.acme.PrintIgnoreRunListener</value>
</property>
</properties>
</configuration>
</plugin>