我尝试使用Java和Maven构建我的第一个可执行规范.我用这个结构创建了一个简单的项目:
specification
|-src
|-test
|-java
|-mypackage
|-MyFeatureTest.java
|-resources
|-MyFeature.feature
Run Code Online (Sandbox Code Playgroud)
在junit测试中MyFeatureTest.java我有这个:
import org.junit.runner.RunWith;
import cucumber.junit.Cucumber;
@RunWith(Cucumber.class)
public class HomepageTest {
}
Run Code Online (Sandbox Code Playgroud)
现在https://github.com/cucumber/cucumber-jvm/wiki/IDE-support说我应该添加以下行:
@Cucumber.Options(paths={"my/super.feature:34"})
Run Code Online (Sandbox Code Playgroud)
我试着修改它
@Cucumber.Options(paths={"src/test/resources/"})
Run Code Online (Sandbox Code Playgroud)
但注释@Cucumber.Options根本不可用.我pom.xml有这种依赖:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.0.0.RC20</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.0.0.RC20</version>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
更新我遗漏了一些东西:黄瓜特征文件必须在子目录中src/test/resources/mypackage/.否则,junit测试不会接收它.
当我将它们放在同一目录中时src/main/test/,我可以运行我的功能测试,所以它对我来说不是一个阻止器.但我想了解整个设置.
这是我的第一个黄瓜项目,我在设置所有内容时遵循了教程。一切似乎都是一样的,但出于某种原因我得到了这个:
\njava.lang.ExceptionInInitializerError。\n原因:java.lang.reflect.InaccessibleObjectException:无法使字段私有最终java.util.Comparator java.util.TreeMap.comparator可访问:模块java.base不“打开java.util”到未命名模块@74ad1f1f
\n知道如何解决这个错误吗?
\n下面我发布了控制台中出现的所有内容以及我的 pom 文件,以防我的依赖项出现问题,尽管教程的 pom 文件中的人员是相同的。
\n这就是我的控制台中显示的所有内容。
\n[31mFailed scenarios:[0m\n[31muni/login/Login.feature:3 [0m# Scenario: Enter the system.\n1 Scenarios ([31m1 failed[0m)\n5 Steps ([31m1 failed[0m, [36m4 skipped[0m)\n0m0.185s\n\njava.lang.ExceptionInInitializerError\n at cucumber.deps.com.thoughtworks.xstream.XStream.setupConverters(XStream.java:820)\n at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:574)\n at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:530)\n at cucumber.runtime.xstream.LocalizedXStreams$LocalizedXStream.<init>(LocalizedXStreams.java:50)\n at cucumber.runtime.xstream.LocalizedXStreams.newXStream(LocalizedXStreams.java:37)\n at cucumber.runtime.xstream.LocalizedXStreams.get(LocalizedXStreams.java:29)\n at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37)\n at cucumber.runtime.Runtime.runStep(Runtime.java:300)\n at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)\n at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)\n at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44)\n at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:102)\n at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)\n at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)\n at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)\n at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)\n at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)\n at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)\n at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)\n at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)\n at org.junit.runners.ParentRunner.run(ParentRunner.java:413)\n at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)\n at cucumber.api.junit.Cucumber.runChild(Cucumber.java:95)\n at cucumber.api.junit.Cucumber.runChild(Cucumber.java:38)\n at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)\n …Run Code Online (Sandbox Code Playgroud) 我们正在考虑在我们的验收测试项目中使用Cucumber.
当我们写scenario在黄瓜feature,我们写的名单Given,When和Then语句.
当我们使用cucumber-jvm项目时Given,When和Then语句与(JUnit)类中的Java方法有关.
我想知道在项目结构中与Given/ When/ 相关的代码的最佳组织是什么Then.我主要担心的是在一个大项目上维护黄瓜测试,其中场景的数量非常重要,特别是关于功能之间共享的项目.
我可以看到至少两种主要方法:
每个功能都与它自己的JUnit类相关.所以,如果我有一个foo/bar/baz.feature黄瓜文件,我会发现相关型号foo.bar.Baz与适当的JUnit类@Given,@When和@Then注释的方法.
独立@Given,@When并且@Then方法进入"主题"类和包.例如,如果在我的黄瓜场景中我有一个语句Given user "foo" is logged,那么带@Given("^user \"([^\"]*)\" is logged$")注释的方法将位于foo.user.User类方法中,但可能,@When稍后在同一个黄瓜场景中使用的方法将在不同的Java类和包中(假设foo.car.RentCar) .
对我来说,第一种方法似乎很好,我可以很容易地做我的黄瓜功能和我的Java代码之间的关系.但缺点是我可能会有很多冗余或代码重复.此外,可能很难找到可能的现有@Given方法,以避免重新创建它(IDE可以提供帮助,但在这里我们使用Eclipse,它似乎没有给出现有Given语句的列表?).
当你在几个黄瓜特征之间共享条件时,另一种方法似乎更好Given,因此我想避免代码重复.这里的缺点是很难在@GivenJava方法和 …
java acceptance-testing cucumber cucumber-jvm cucumber-junit
我正在使用Cucumber在我的应用程序中自动测试服务和控制器.另外,我@RunWith(Cucumber.class)
在测试步骤中使用了Cucumber Junit跑步者.我需要实例化我的控制器,并想知道我是否可以使用Spring自动装配它.下面的代码显示了我想要做的事情.
public class MvcTestSteps {
//is it possible to do this ????
@Autowired
private UserSkillsController userSkillsController;
/*
* Opens the target browser and page objects
*/
@Before
public void setup() {
//insted of doing it like this???
userSkillsController = (UserSkillsController) appContext.getBean("userSkillsController");
skillEntryDetails = new SkillEntryRecord();
}
Run Code Online (Sandbox Code Playgroud) 我有一个黄瓜和maven的项目,我也在使用JUnit.
我能够从Eclipse成功运行和构建我的项目.
现在我想在另一个系统中从命令行运行测试,该系统确实(应该)没有安装eclipse或者黄瓜.我有一个想法,我们可以从jar创建一个JAR,我们可以通过java cli命令运行测试.
下面是我尝试运行测试的组合,我也粘贴了pom.xml和RunCukesTest.java文件.
的pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>pmc</groupId>
<artifactId>se</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>storeEnabler</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.4</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.52.0</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.11-beta3</version>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.8.0</version>
</dependency>
</dependencies>
<build>
<testResources> …Run Code Online (Sandbox Code Playgroud) 我有一堆带有各种黄瓜标签的IT案例.在我的主要跑步者课程中,我想排除所有具有@one或@two的场景.所以,下面是我尝试选项1的选项
@CucumberOptions(tags=Array("~@one,~@two"), .....)
Run Code Online (Sandbox Code Playgroud)
或选项2
@CucumberOptions(tags=Array("~@one","~@two").....
Run Code Online (Sandbox Code Playgroud)
当我尝试使用选项一时,用@two标记的测试用例开始执行,而第二个选项则没有.根据黄瓜文档,当标记被提及时,将保持OR "@One,@Two".如果是这种情况,为什么不排除工作方式相同,即第一种选择?
更新:这段代码是用scala编写的.
我有以下项目结构:
MyProject
--src
--test
--acceptance
--step_definitions
--features
--unit
Run Code Online (Sandbox Code Playgroud)
我希望能够在测试/单元中声明的单元测试中分别在Maven中运行我的黄瓜测试(在测试/验收中),以便它们可以在不同的CI构建计划中运行等.我正在使用cucumber-junit所以每个验收测试的"跑步者"都是用JUnit编写的.
这可能吗?
我有一个Cucumber-JVM,JUnit,Selenium设置.我通过RunSmokeTests.java在Eclipse中使用JUnit来启动运行.我还设置了一个maven配置文件来从命令行运行测试,将来可能还有Jenkins.
当测试运行时,其中一些可能会失败,主要是由于应用程序花费的时间超过预期.然后我必须重新运行这些场景.目前我通过手动将@rerun标签附加到失败然后运行的标签来运行它们RunReruns.java,这类似于RunSmokeTest.java带@rerun标签.
随着自动化测试数量的增加,标记测试并开始运行并清除标签非常耗时.有没有使用Cucumber-JVM重新运行失败测试的自动化方法?
RunSmokeTests.java
package testGlueClasses;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@Cucumber.Options(features = "src/test/java", strict = true, format = {
"html:target/CucumberReport", "json:target/JSON/Cucumber.json",
"FrameworkCore.CustomTestReporter" }, tags = { "@SmokeTest" }, glue = {
"FrameworkCore", "MyApp.Utils", "MyApp.StepDefinitions" })
public class RunSmokeTests {
}
Run Code Online (Sandbox Code Playgroud)
Maven片段:
<profile>
<id>smoke</id>
<properties>
<include.tests>
**/RunSmokeTests.java
</include.tests>
</properties>
</profile>
Run Code Online (Sandbox Code Playgroud) 如何使用Maven在以下位置运行我的黄瓜测试.
源文件夹的src/main/java'和'src/main/resources'包括在每个源文件夹中创建的包'com.testing.TestProject.login'中的步骤定义和功能文件.
我在POM文件中包含了插件和依赖项,但是当我运行maven阶段集成测试时,黄瓜测试没有被执行.
我是Maven的新手.请让我知道要在POM文件中包含什么来运行Maven的黄瓜测试.
这是我的POM文件:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.testing</groupId>
<artifactId>MyMavenProject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MyMavenProject</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<cucumber-jvm.version>1.1.5</cucumber-jvm.version>
<selenium.version>2.39.0</selenium.version>
<junit.version>4.11</junit.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<executableDependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
</executableDependency>
<mainClass>cucumber.api.cli.Main</mainClass>
<arguments>
<argument>--format</argument>
<argument>junit:target/cucumber-junit-report/allcukes.xml</argument>
<argument>--format</argument>
<argument>pretty</argument>
<argument>--format</argument>
<argument>html:target/cucumber-html-report</argument>
<argument>--tags</argument>
<argument>@login</argument>
<argument>--glue</argument>
<argument>com/</argument>
<argument>src/</argument>
</arguments>
</configuration>
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
<version>1.1.5</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency> …Run Code Online (Sandbox Code Playgroud)