0

I need to run certain tests depending using JUnitCore and Categories but I can't find a way to make it work, can you please take a look and let me know if this is valid?

I have the following TestSuite called:

@RunWith(Categories.class)
@IncludeCategory(FeatureA.class) //this is the interface required as per categories documenation
@SuiteClasses( { AllTests.class } ) //imagine that AllTests contains all my tests
public class FeatureASuite {

} //if I'm not mistaken this configuration 
  // will go over all my tests and 
  // pick up only the ones with category FeatureA

And then I have a main class that will handle the execution as follows:

public static void main(String[] args) {
    List<Class<?>> classes = new ArrayList<Class<?>>(); //classes collection
    boolean featureA= true; //as this is an example featureA is always enabled
    if(featureA) { //if feature A enabled then..
        classes.add(FeatureASuite.class); //...add the feature A suite.
    }
        JUnitCore jUnitCore = new JUnitCore(); //create the facade
        jUnitCore.runClasses(classes.toArray(new Class[classes.size()])); //run the classes specified

}

After executing the code the tests are not run. I have tried this with a different runner (instead of using Categories.class I have tried Suite.class) and tests are executed, however I need to specify categories per test method and Suite.class is not hitting that mark.

user1336321
  • 144
  • 1
  • 1
  • 10

1 Answers1

0

I have found why my approach was not working, the implementation above is actually correct, the issue (what I consider a junit bug) is in how Junit reacts to RunWith, if any of the classes under SuiteClasses contains RunWith annotation for any reason the execution will stop before even starting to run a first test.

user1336321
  • 144
  • 1
  • 1
  • 10
  • If you think you found a bug in JUnit, then please create a reproducible test case and file a bug at https://github.com/junit-team/junit – NamshubWriter Jun 18 '15 at 13:13