自分でTestClassMethodsRunner
を作成してください(これは文書化されていないか、今は見つかりません)。
TestClassMethodsRunner
はすべてのテストケースを実行し、フィルタリングされたTestClassMethodsRunner
を設定できます。
あなたがしなければならないのは、TestMethodRunner createMethodRunner(Object, Method, RunNotifier)
メソッドを上書きすることだけです。これは単純なハックソリューションです。このテストランナーで
public class FilteredTestRunner extends TestClassMethodsRunner {
public FilteredTestRunner(Class<?> aClass) {
super(aClass);
}
@Override
protected TestMethodRunner createMethodRunner(Object aTest, Method aMethod, RunNotifier aNotifier) {
if (aTest.getClass().getName().contains("NOT")) {
return new TestMethodRunner(aTest, aMethod, aNotifier, null) {
@Override
public void run() {
//do nothing with this test.
}
};
} else {
return super.createMethodRunner(aTest, aMethod, aNotifier);
}
}
}
、あなたは文字列「NOT」を含まないすべてのテストを実行します。他のものは無視されます:)あなたのTestRunnerクラスの@RunWith
アノテーションをテストに追加してください。
@RunWith(FilteredTestRunner.class)
public class ThisTestsWillNOTBeExecuted {
//No test is executed.
}
@RunWith(FilteredTestRunner.class)
public class ThisTestsWillBeExecuted {
//All tests are executed.
}
createMethodRunner
方法では、実行するか、新しいのcriteriasを導入しなければならないテストのリストに対して、現在のテストを確認することができます。
これで幸運を祈る!
もっと良い解決策のヒントがありがとう!
OK、それははるかにエレガントです私の解決策よりも:) – guerda
私は数日間この同じ(または少なくとも非常に似たような)問題に苦労してきました。 Powermockで独自の@RunWith(PowermockRunner.class)アノテーションが必要なFilteredRunnerを使用する場合はどうなりますか? –
偉大な答えですが、今は時代遅れです。私はTestClassRunnerの代わりにBlockJUnit4ClassRunnerを使う必要があると思います。 – Illidanek