Ignore JUnit Test

I have a test, and I want it to not run what is good practice: install Ignoreinside the test? @Deprecated?

I would like not to run it, but with a message saying that I have to make changes for the future in order to run it.

+5
source share
2 answers

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>
+12

, . :

@RunWith(Suite.class)
@Suite.SuiteClasses({
WorkItemTOAssemblerTestOOC.class,
WorkItemTypeTOAssemblerTestOOC.class,
WorkRequestTOAssemblerTestOOC.class,
WorkRequestTypeTOAssemblerTestOOC.class,
WorkQueueTOAssemblerTestOOC.class
})
public class WorkFlowAssemblerTestSuite {

}
0

All Articles