I'm testing extensively with JUnit and sometimes - while debugging my code - I want (temporary) only run a single @Test
of my @RunWith(Arquillian.class)
test class. Currently I'm adding a @Ignore
to all other tests and wondering if something like @IgnoreOther
does exist.
Are there better solutions to ignore all other tests?
The simplest way is to replace all @Test
to //###$$$@Test
. Then when your debugging is finished replace //###$$$@Test
to @Test
.
Moreover typically IDEs allow running one test only. For example in Eclipse you can do it from Outline view.
Just my two cents. You can try to use Junit Rules as @srkavin suggested.
Here is an example.
package org.foo.bar;
import org.junit.rules.MethodRule;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
public class SingleTestRule implements MethodRule {
private String applyMethod;
public SingleTestRule(String applyMethod) {
this.applyMethod = applyMethod;
}
@Override
public Statement apply(final Statement statement, final FrameworkMethod method, final Object target) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
if (applyMethod.equals(method.getName())) {
statement.evaluate();
}
}
};
}
}
package org.foo.bar;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
public class IgnoreAllTest {
@Rule
public SingleTestRule test = new SingleTestRule("test1");
@Test
public void test1() throws Exception {
System.out.println("test1");
}
@Test
public void test2() throws Exception {
Assert.fail("test2");
}
@Test
public void test3() throws Exception {
Assert.fail("test3");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With