JUnitCore とカテゴリを使用して特定のテストを実行する必要がありますが、それを機能させる方法が見つかりません。確認して、これが有効かどうか教えてください。
次のTestSuiteを呼び出しました:
@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
そして、次のように実行を処理するメイン クラスがあります。
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
}
コードを実行した後、テストは実行されません。別のランナーでこれを試しました (Categories.class を使用する代わりに、Suite.class を試しました)。テストは実行されますが、テスト メソッドごとにカテゴリを指定する必要があり、Suite.class はそのマークに達していません。