在 IntelliJ 运行程序中配置 @RunWith 以使用 CucumberWithSerenity.class 而不是 Cucumber.class

Configuring @RunWith to use CucumberWithSerenity.class instead of Cucumber.class in IntelliJ runners

我有一个 gradle + Serenity + RestAssured 自动检查套件设置,我通常 运行 通过 shell 会话中的 gradle 命令,但有时我需要 运行 使用 IntelliJ 的单个场景。

当我在 IntelliJ 上 运行 场景时,我通常会收到很多这样的警告:

8312 [main] WARN cucumber.runtime.SerenityBackend - It looks like you are 
running a feature using @RunWith(Cucumber.class) 
instead of @RunWith(CucumberWithSerenity.class). 
Are you sure this is what you meant to do?

我想知道在哪里以及如何在 IntelliJ 中配置 Run/Debug 配置,以便 运行 使用 CucumberWithSerenity.class 检查并修复警告。

我正在使用以下依赖项:

serenity-rest-assured:1.9.31
serenity-core:1.9.31
serenity-cucumber:1.9.12

IntelliJ 版本 2018.1.5(社区版)

以下步骤来自 John Ferguson Smart 的博客,Serenity-BDD 的作者(考虑到您已经安装了 Cucumber for Java 插件)。

Running Cucumber with Serenity feature files directly from IntelliJ:

IntelliJ provides excellent integrated support for Cucumber feature files. You can even run features simply by right-clicking on the feature file. But this won’t work when you are using Cucumber with Serenity, as Serenity needs to instrument the feature file before execution. Fortunately, this is easy to fix. Here’s how:

  • Click on the feature file you want to run
  • In the Run menu Select Run…
  • In the contextual menu, select the feature, then “Edit…”
  • You should now see the ‘Edit Configuration Settings’ window. Set the main class to ‘net.serenitybdd.cucumber.cli.Main’
  • Change the Glue field to the root package of your project (or of your step definitions)
  • Click Apply

Now you can run your feature directly by right-clicking on the feature file.

P.S。并非所有版本的 Java 插件 Cucumber 都能正常工作,尤其是当您刚刚将 IntelliJ IDEA 更新到最新版本时。我可以确认下一个设置是否正常工作:

  • IntelliJ IDEA 2018.2.3(社区版);
  • 黄瓜 Java 插件版本 182.3934;
  • net.serenity-bdd:宁静核心:2.0.6;
  • net.serenity-bdd:宁静黄瓜:1.9.18