我有以下Given
声明:
ServiceSatus.feature:
Given I run a request for service status with the following options
|field1 |field2 |field3 |
|all |1517029200 |5234817 |
StepDefinition.java:
private HashMap<String,String> options = new HashMap<String, String>();
@Given("I run a request for service status with the following options")
public void i_run_a_request_for_service_status(ExamplesTable featureOptions) {
options.put("field1",featureOptions.getRows().get(0).get("field1"));
options.put("field2",featureOptions.getRows().get(0).get("field2"));
options.put("field3",featureOptions.getRows().get(0).get("field3"));
}
Cucumber将此识别为有效的Examples Table
,但是我收到的错误是它不是地图或列表类型。
黄瓜例外:不是地图或列表类型:class org.jbehave.core.model.ExamplesTable
我的功能文件中是否存在某种类型的语法错误?
修改 我在jUnit的基础上使用了jBehave ExampleTables,并且使用了jUnit的黄瓜。
的pom.xml:
依赖关系:
<properties>
<serenity.version>1.9.1</serenity.version>
<serenity.maven.version>1.5.8</serenity.maven.version>
<junit.version>4.12</junit.version>
<slf4j.version>1.6.1</slf4j.version>
<maven.failsafe.plugin.version>2.18</maven.failsafe.plugin.version>
<maven.compiler.plugin.version>3.2</maven.compiler.plugin.version>
<serenity.cucumber.version>1.9.1</serenity.cucumber.version>
</properties>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.0.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-core</artifactId>
<version>${serenity.version}</version>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-junit</artifactId>
<version>${serenity.version}</version>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-cucumber</artifactId>
<version>${serenity.cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-rest-assured</artifactId>
<version>${serenity.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-maven-plugin</artifactId>
<version>4.1.3</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160810</version>
</dependency>
插件:
<plugin>
<groupId>net.serenity-bdd.maven.plugins</groupId>
<artifactId>serenity-maven-plugin</artifactId>
<version>${serenity.maven.version}</version>
<dependencies>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-core</artifactId>
<version>${serenity.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>serenity-reports</id>
<phase>post-integration-test</phase>
<goals>
<goal>aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
答案 0 :(得分:1)
JBehave和Cucumber模型混合在一起:
org.jbehave.core.model.ExamplesTable
cucumber.api.DataTable
这些类是类似的,它们代表同一类对象(BDD表),但属于不同的库。
最好选择一个BDD框架并遵循其模型。但是,如果仍然需要在org.jbehave.core.model.ExamplesTable
上下文中使用Cucumber
作为步骤输入参数,则应实现自定义转换器:https://static.javadoc.io/info.cukes/cucumber-core/1.2.5/cucumber/api/Transformer.html