Cucumber, Java8: 查找 lambda 表达式定义的步骤的用法
Cucumber, Java8: find usage of step defined by lambda expression
目前在我们项目的测试中,我们不再使用带注释的步骤定义,例如:
public class Steps {
@Given("^Step name$")
void methodName() {
// do sth
}
}
到 lambda 表达式:
public class Steps implements En {
public Steps() {
Given("^Step name$", () ->
// do sth
);
}
}
当使用 Intellij Cucumber Java 插件时,很容易找到某些步骤的用法,因为它会查找带注释的方法的用法(我想)。
但是现在,我们必须手动搜索作为参数传递的正则表达式。
我的第一个问题是:是否有使用 lambda 表达式的巧妙方法?
此外:当使用Intellij的版本控制工具和提交包含大量步骤定义的文件时,代码分析工具将永远持续下去(我猜这是因为构造函数必须编写大量代码)。
所以第二个问题是:既然步骤库不可能缩水,步骤用法搜索又经常用到,那换回不是个好主意吗到 Ye Olde Way,即使用带注释的方法?
查找 java-8 样式步骤定义的用法尚不可用。可以投票并关注此请求:IDEA-144648.
正在使用
- IntelliJ IDEA 2018.1.5
- 'Cucumber for Java' 插件 181.5281.24
pom.xml
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<version.cucumber>3.0.2</version.cucumber>
<!-- following versions were also checked -->
<!--<version.cucumber>2.4.0</version.cucumber>-->
<!--<version.cucumber>2.3.1</version.cucumber>-->
</properties>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java8</artifactId>
<version>${version.cucumber}</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${version.cucumber}</version>
<scope>test</scope>
</dependency>
</dependencies>
userdata.feature
Feature: demo for java8 glue classes
Scenario: user login on home page
Given user is on home page
When user navigate to login page
And user enters credentials to login
Then message displayed login successfully
glue/StepPojo.java
package glue;
import cucumber.api.PendingException;
import cucumber.api.java8.En;
public class StepPojo implements En {
public StepPojo() {
Given("^User is on Home Page$", () -> {
throw new PendingException();
});
When("^User Navigate to LogIn Page$", () -> {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
});
And("^User enters Credentials to LogIn$", () -> {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
});
Then("^Message displayed Login Successfully$", () -> {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
});
}
}
class StepPojo.java
是由 Cucumber 插件通过在功能文件中选择一个步骤时按 ALT+ENTER
创建的。
特征文件之前显示为
定义后的步骤为
[
当您在按下 CTRL
键的同时将鼠标悬停在一个步骤上时,它看起来像
当您在按下 CTRL
键的同时单击一个步骤时,您将跳转到相应的方法,例如
Given("^User is on Home Page$", () -> {
throw new PendingException();
});
目前在我们项目的测试中,我们不再使用带注释的步骤定义,例如:
public class Steps {
@Given("^Step name$")
void methodName() {
// do sth
}
}
到 lambda 表达式:
public class Steps implements En {
public Steps() {
Given("^Step name$", () ->
// do sth
);
}
}
当使用 Intellij Cucumber Java 插件时,很容易找到某些步骤的用法,因为它会查找带注释的方法的用法(我想)。 但是现在,我们必须手动搜索作为参数传递的正则表达式。
我的第一个问题是:是否有使用 lambda 表达式的巧妙方法?
此外:当使用Intellij的版本控制工具和提交包含大量步骤定义的文件时,代码分析工具将永远持续下去(我猜这是因为构造函数必须编写大量代码)。
所以第二个问题是:既然步骤库不可能缩水,步骤用法搜索又经常用到,那换回不是个好主意吗到 Ye Olde Way,即使用带注释的方法?
查找 java-8 样式步骤定义的用法尚不可用。可以投票并关注此请求:IDEA-144648.
正在使用
- IntelliJ IDEA 2018.1.5
- 'Cucumber for Java' 插件 181.5281.24
pom.xml
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<version.cucumber>3.0.2</version.cucumber>
<!-- following versions were also checked -->
<!--<version.cucumber>2.4.0</version.cucumber>-->
<!--<version.cucumber>2.3.1</version.cucumber>-->
</properties>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java8</artifactId>
<version>${version.cucumber}</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${version.cucumber}</version>
<scope>test</scope>
</dependency>
</dependencies>
userdata.feature
Feature: demo for java8 glue classes
Scenario: user login on home page
Given user is on home page
When user navigate to login page
And user enters credentials to login
Then message displayed login successfully
glue/StepPojo.java
package glue;
import cucumber.api.PendingException;
import cucumber.api.java8.En;
public class StepPojo implements En {
public StepPojo() {
Given("^User is on Home Page$", () -> {
throw new PendingException();
});
When("^User Navigate to LogIn Page$", () -> {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
});
And("^User enters Credentials to LogIn$", () -> {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
});
Then("^Message displayed Login Successfully$", () -> {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
});
}
}
class StepPojo.java
是由 Cucumber 插件通过在功能文件中选择一个步骤时按 ALT+ENTER
创建的。
特征文件之前显示为
定义后的步骤为
[
当您在按下 CTRL
键的同时将鼠标悬停在一个步骤上时,它看起来像
当您在按下 CTRL
键的同时单击一个步骤时,您将跳转到相应的方法,例如
Given("^User is on Home Page$", () -> {
throw new PendingException();
});