In my project, I have acceptance tests which take a long time to run. When I add new features to the code and write new tests, I want to skip some existing test cases for the sake of time. I am using Spring 3 and junit 4 using SpringJUnit4ClassRunner. My idea is to create an annotation (@Skip or something) for the test class. I am guessing I would have to modify the runner to look for this annotation and determine from system properties if a test class should be included while testing. My question is, is this easily done? Or am I missing an existing functionality somewhere which will help me?
Thanks. Eric
Annotate your class (or unit test methods) with @Ignore in Junit 4 and @Disabled in Junit 5 to prevent the annotated class or unit test from being executed.
Ignoring a test class:
@Ignore
public class MyTests {
@Test
public void test1() {
assertTrue(true);
}
}
Ignoring a single unit test;
public class MyTests {
@Test
public void test1() {
assertTrue(true);
}
@Ignore("Takes too long...")
@Test
public void longRunningTest() {
....
}
@Test
public void test2() {
assertTrue(true);
}
}
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