0

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 はそのマークに達していません。

4

1 に答える 1

0

上記の実装は実際には正しいです。問題 (私が junit のバグと見なすもの) は、Junit が RunWith にどのように反応するかにあります。SuiteClasses の下のクラスのいずれかに何らかの理由で実行最初のテストの実行を開始する前に停止します。

于 2015-05-22T17:12:21.720 に答える