概要:たとえばx
、テストの数が失敗した場合など、実行中のキュウリテストパックを途中で停止したい場合があります。
これは問題なく実行できますがplugin = {json:...}
、テストの停止時にjsonファイル()を生成する必要があります。これは実行可能ですか?
私がこれまでに試したこと:
Cucumber.java: runtime.getEventBus().send.....
@Override
protected Statement childrenInvoker(RunNotifier notifier) {
final Statement features = super.childrenInvoker(notifier);
return new Statement() {
@Override
public void evaluate() throws Throwable {
features.evaluate();
runtime.getEventBus().send(new TestRunFinished(runtime.getEventBus().getTime()));
runtime.printSummary();
}
};
}
runtime
フィールドにアクセスしたいと思っていましたが、private
修飾子があります。また、経由でアクセスしようとしましたreflections
が、必要なものが正確に得られていません。
かなり汚いが、実用的な解決策を見つけて、私が必要なものを手に入れました。誰かが必要になるかもしれない場合に備えて、ここに私の解決策を投稿してください。
public final class Foo extends Cucumber {
static Runtime runtime;
/**
* Constructor called by JUnit.
*
* @param clazz the class with the @RunWith annotation.
* @throws IOException if there is a problem
* @throws InitializationError if there is another problem
*/
public Foo(Class clazz) throws InitializationError, IOException {
super(clazz);
}
@Override
protected Runtime createRuntime(ResourceLoader resourceLoader, ClassLoader classLoader, RuntimeOptions runtimeOptions) throws InitializationError, IOException {
runtime = super.createRuntime(resourceLoader, classLoader, runtimeOptions);
return runtime;
}
}
public final class ParentHook {
@Before
public void beforeScenario(Scenario myScenario) {
}
@After
public void afterScenario() {
if (your condition to stop the test) {
//custom handle to stop the test
myHandler.pleaseStop();
Foo.runtime.getEventBus().send(new TestRunFinished(Foo.runtime.getEventBus().getTime()));
}
}
}
Foo.class
例:の@RunWith(Foo.class)
代わりに次の方法でテストを実行する必要があります。@RunWith(Cucumber.class)
ここではそれほど価値はありませんが、現時点で必要なものに適合しています。Cucumberがこれを箱から出して行う方法を提供することを願っています。より良い方法がある場合は、ここに投稿してください。確認されたら回答を受け付けます。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加