Junit: ignore or skip entire test class
I have a scenario where I want to ignore an entire junit test class containing a bunch of test methods based on a particular boolean value that I am reading from a properties file. This property is a boolean value. If false, the entire test class should be skipped from execution.
I tried using the @Ignore annotation but not sure if that can be used for such a scenario.
Please, help.
Hello,
+3
source to share
1 answer
AFAIK, @Ignore
won't help you. Try using it Assume
with something like this (if the guess doesn't work, then the test looks like it was ignored. Of course, you can put a sentence in each test method if the solution is not reasonable):
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.Test;
public class TestWithAssume {
@BeforeClass
public static void beforeClass() throws Exception {
Assume.assumeTrue(true); // LOAD THE VALUE FROM THE PROPERTIES FILE AS NEEDED...
}
@Test
public void test1() throws Exception {
}
@Test
public void test2() throws Exception {
}
}
+3
source to share