4

I have a scenario in which I want to ignore the entire junit test class containing a set of test methods based on a specific Boolean value which 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 @Ignore annotation but not sure whether that can be used for such scenario.

Please help.

Regards,

1
  • @Ignore cannot be used, because it has no arguments. Sep 30, 2014 at 8:04

1 Answer 1

6

AFAIK, @Ignore won't help you here. Try using Assume with something similar to this (if the assumption fails then the test will look as ignored. Of course you can put the assume in every test method if the decision is not class wise):

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 {
    }

}
2
  • Hi Shlomi, is it possible to use @BeforeClass annotation if my Test class extends some Base class / Parent class ?
    – Anand03
    Sep 30, 2014 at 13:24
  • I think so... The best way is to try and see. Write a simple construction that imitates your code like I did with the simple snippet and add println() at each stage. Run it and see what was executed and in what order.
    – shlomi33
    Sep 30, 2014 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.