我想将我的验收测试打包到一个可执行 JAR 中,其中包含运行测试和生成报告所需的所有库。我还想运行所有测试或单个测试。
到目前为止,我能够运行所有测试,尽管在我在 serenity.properties 中指定的位置生成报告,但没有生成 index.html。
通常,我会使用 maven verify 目标运行我的测试,该目标将运行 serenity-maven-plugin,但由于我是从 JAR 运行的,我不确定如何实现相同的目标。
我有一个主类,如下所示:
@RunWith(CucumberWithSerenity.class)
@CucumberOptions(features = "classpath:com/cfhayes/test/LookupADefinition.feature")
public class DefinitionTestSuite {
public static void main(String[] args) throws Exception {
JUnitCore.main("com.cfhayes.test.DefinitionTestSuite");
}
}
Run Code Online (Sandbox Code Playgroud)
我的功能文件使用标签,以便我可以指定要运行的单个场景:
Feature: Lookup a definition
@TEST-0001
Scenario: Looking up the definition of 'apple'
Given the user is on the Wikionary home page
When the user looks up the definition of the word 'apple'
Then they should see the definition 'A common, round fruit produced by the …Run Code Online (Sandbox Code Playgroud) 我正在为测试每个功能的Spring启动应用程序编写cucumber-java单元测试.当我与spring boot集成时,@ Autowired类会抛出NullPointer异常.
春季启动应用程序类,
@SpringBootApplication
public class SpringBootCucumberTest {
public static void main(String[] args) {
SpringApplication.run(SpringBootCucumberTest.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
要测试的课程,
@Component
public class Library {
private final List<BookVo> store = new ArrayList<BookVo>();
public void addBook(final BookVo BookVo) {
this.store.add(BookVo);
}
}
Run Code Online (Sandbox Code Playgroud)
黄瓜单位类,
@RunWith(Cucumber.class)
@CucumberOptions(format = "pretty", features = "src/test/resources")
public class BookSearchTest {
}
Run Code Online (Sandbox Code Playgroud)
黄瓜定义类,
public class BookSearchSteps extends AbstractDefinition{
@Autowired
private Library library;
private List<BookVo> result = new ArrayList<BookVo>();
@Given(".+book with the title '(.+)', written …Run Code Online (Sandbox Code Playgroud) 我想匹配以下 BDD 之一:
Then the response status should be "200"
Then response status should be "200"
Run Code Online (Sandbox Code Playgroud)
我想让“the”可选。我希望这两个规则映射到同一步骤。
这是我的尝试,但它不起作用:
@Then("^(?:the | )response status should be \"([^\"]*)\"$")
public void the_response_status_should_be(String arg1) {
...
}
Run Code Online (Sandbox Code Playgroud) 我想在运行时使用 Java 获取当前的功能文件名。我在钩子中有场景信息但无法获取功能文件
@Before
public void before(final Scenario scenario) {
this.scenario = scenario;
}
Run Code Online (Sandbox Code Playgroud)
我们是否有类似的东西来获取当前的功能文件名?我正在使用黄瓜版本 1.2.4
我有一个用@Async 注释的方法说
@Async public void createArticles(long Id){}
但我只是想对这种方法进行黄瓜测试。是否可以同步测试?
我需要自动化一些网络服务,我为此创建了一些方法,并且我想使用 Cucumber 来实现这一点,但我不知道如何在下一步中使用返回值。
所以,我有这个功能:
Feature: Create Client and place order
Scenario: Syntax
Given I create client type: "66"
And I create for client: "OUTPUTVALUEfromGiven" an account type "123"
And I create for client: "OUTPUTVALUEfromGiven" an account type "321"
And I want to place order for: "outputvalueFromAnd1"
Run Code Online (Sandbox Code Playgroud)
我有这个步骤:
public class CreateClientSteps {
@Given("^I create client type: \"([^\"]*)\"$")
public static String iCreateClient(String clientType) {
String clientID = "";
System.out.println(clientType);
try {
clientID = util.createClient(clientType);
} catch (IOException e) {
e.printStackTrace();
}
return …Run Code Online (Sandbox Code Playgroud) 是否可以从java .properties文件中获取黄瓜选项值?
在此 SO帖子中,它表明它是从CLI传递的。
这是我的示例课:
@RunWith(Cucumber.class)
@CucumberOptions(
features = {"resources/features/"},
glue = {"classpath:com/"},
tags = {"@foo, @bar"}
)
public class UITestRunner {
}
Run Code Online (Sandbox Code Playgroud)
我不想在这里对标签进行硬编码,而是从属性文件中获取标签。任何帮助表示赞赏!
我想从java代码运行黄瓜功能文件.
目前我们正在运行JUnit Runner
package com.compareglobalgroup.testscript;
import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;
@CucumberOptions(features = { "src/test/resources/feature/BB" }, glue = { "com.compareglobalgroup.stepdefs.BB",
"com.compareglobalgroup.cucumber.hooks" }, plugin = {
"json:cucumberreport/json/cucumberreport.json" }, tags = { ""
+ "@Test" })
public class TestRunnerBB extends AbstractTestNGCucumberTests {
}
Run Code Online (Sandbox Code Playgroud)
我不想使用它,而是想使用java程序运行它,因为我想在运行时从命令行或jenkins传递标记.
我是 UnitTesting 和 Cucumber 的新手,今天我尝试在 Intelij 和 Eclipse 中实现教程中的一个简单示例,当我尝试运行 TestRunner.java 时,我遇到了相同的错误。
我的 pom.xml:
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
文件.feature
Feature: User Login
User should be able to login using valid credentials
Scenario: Testing login with valid credentials
Given I am on login page
When I enter username as "jsmith" and password as "demo1234"
And I submit login page
Then I redirect to user home page
Run Code Online (Sandbox Code Playgroud)
测试运行器.java
package com.unit.runner;
import …Run Code Online (Sandbox Code Playgroud) 如果我有这样的场景 outilne:
Scenario Outline: test
Given I am on page X
When I fill the <name> on field <fieldID>
And I click on Ok button
Then I should see something
Examples:
name | fieldID |
"Jhon" | "name1"|
"Max" | "name2" |
"Paul" | "name3"|
Run Code Online (Sandbox Code Playgroud)
我可以只运行“何时”步骤 3 次,然后单击确定吗?还是我必须编写所有 3 个不同的步骤?我需要这 3 个信息才能点击确定,这不像我用不同的登录值测试 3 次的登录
cucumber-java ×10
cucumber ×6
cucumber-jvm ×4
java ×4
bdd ×3
spring ×2
gherkin ×1
qaf ×1
selenium ×1
unit-testing ×1