Java JUNIT作为JVM测试运行myfeature.feature时出错>;potes.cucumberjvm.test.RunCucumberTest>;初始化错误

Java JUNIT作为JVM测试运行myfeature.feature时出错>;potes.cucumberjvm.test.RunCucumberTest>;初始化错误,java,maven,junit,cucumber,cucumber-junit,Java,Maven,Junit,Cucumber,Cucumber Junit,测试数据:- 1) Java版本“1.8.0_121”Java(TM)SE运行时环境(构建1.8.0_121-b13)Java热点(TM)64位服务器虚拟机(构建25.121-b13,混合模式) 2) Eclipse面向Java开发人员的IDE版本:Neon.2发行版(4.6.2)构建id:20161208-0600 3) OS Microsoft Windows 10 Home-64位 myFeature.feature Feature: This is my dummy feature fi

测试数据:-

1) Java版本“1.8.0_121”Java(TM)SE运行时环境(构建1.8.0_121-b13)Java热点(TM)64位服务器虚拟机(构建25.121-b13,混合模式)

2) Eclipse面向Java开发人员的IDE版本:Neon.2发行版(4.6.2)构建id:20161208-0600

3) OS Microsoft Windows 10 Home-64位

myFeature.feature

Feature: This is my dummy feature file

Scenario: This is my first dummy scenario
Given This is my first dummy given step
When This is my second dummy given step
Then This is my third dummy given step
steps.java

package com.cucumber.mavenCucumberPrototype;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class steps
{
@Given("^This is my first dummy given step$")
public void This_is_my_first_dummy_given_step() throws Throwable
{
    System.out.println("Executed the first given step");
}
@When("^This is my second dummy given step$")
public void This_is_my_second_dummy_given_step() throws Throwable
{
    System.out.println("Executed the first when step");
}
@Then("^This is my third dummy given step$")
public void This_is_my_third_dummy_given_step() throws Throwable
{
    System.out.println("Executed the first then step");
}
}
package com.cucumber.mavenCucumberPrototype;

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(
    features = "classpath:features"
            )

public class RunnerTest
{

}
RunnerTest.java

package com.cucumber.mavenCucumberPrototype;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class steps
{
@Given("^This is my first dummy given step$")
public void This_is_my_first_dummy_given_step() throws Throwable
{
    System.out.println("Executed the first given step");
}
@When("^This is my second dummy given step$")
public void This_is_my_second_dummy_given_step() throws Throwable
{
    System.out.println("Executed the first when step");
}
@Then("^This is my third dummy given step$")
public void This_is_my_third_dummy_given_step() throws Throwable
{
    System.out.println("Executed the first then step");
}
}
package com.cucumber.mavenCucumberPrototype;

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(
    features = "classpath:features"
            )

public class RunnerTest
{

}
POM.XML

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>com.cucumber</groupId>
<artifactId>mavenCucumberPrototype</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>mavenCucumberPrototype</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.2.5</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-picocontainer</artifactId>
        <version>1.2.5</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.2.5</version>
    </dependency>
</dependencies>
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>

    </pluginManagement>
</build>
命令行输出:-

C:\Users\Pragati Chaturvedi\workspace\mavenCucumberPrototype>mvn clean 
install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building mavenCucumberPrototype 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ 
mavenCucumberPrototype ---
[INFO] Deleting C:\Users\Pragati 
Chaturvedi\workspace\mavenCucumberPrototype\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ 
mavenCucumberPrototype ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\Pragati 
Chaturvedi\workspace\mavenCucumberPrototype\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ 
mavenCucumberPrototype ---
[INFO] Nothing to compile - all classes are up to date
 [INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ mavenCucumberPrototype ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] skip non existing resourceDirectory C:\Users\Pragati 
   Chaturvedi\workspace\mavenCucumberPrototype\src\test\resources
   [INFO]
    [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ 
   mavenCucumberPrototype ---
  [INFO] Changes detected - recompiling the module!
  [INFO] Compiling 2 source files to C:\Users\Pragati 
  Chaturvedi\workspace\mavenCucumberPrototype\target\test-classes
  [INFO]
  [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ 
  mavenCucumberPrototype ---
  [INFO] Surefire report directory: C:\Users\Pragati 
  Chaturvedi\workspace\mavenCucumberPrototype\target\surefire-reports

   -------------------------------------------------------
  T E S T S
-------------------------------------------------------
Running com.cucumber.mavenCucumberPrototype.RunnerTest
No features found at [classpath:features]

 0 Scenarios
 0 Steps
 0m0.000s
 Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.331 sec
 Results :
  Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
 [INFO]
 [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ mavenCucumberPrototype 
  ---
 [WARNING] JAR will be empty - no content was marked for inclusion!
 [INFO] Building jar: C:\Users\Pragati 
 Chaturvedi\workspace\mavenCucumberPrototype\target\mavenCucumberPrototype-
 0.0.1-SNAPSHOT.jar
 [INFO]
 [INFO] --- maven-install-plugin:2.4:install (default-install) @ 
 mavenCucumberPrototype ---
 [INFO] Installing C:\Users\Pragati 
 Chaturvedi\workspace\mavenCucumberPrototype\target\mavenCucumberPrototype-
 0.0.1-SNAPSHOT.jar to C:\Users\Pragati 
 Chaturvedi\.m2\repository\com\cucumber\mavenCucumberPrototype\0.0.1-
 SNAPSHOT\mavenCucumberPrototype-0.0.1-SNAPSHOT.jar
 [INFO] Installing C:\Users\Pragati 
 Chaturvedi\workspace\mavenCucumberPrototype\pom.xml to C:\Users\Pragati 
 Chaturvedi\.m2\repository\com\cucumber\mavenCucumberPrototype\0.0.1-
  SNAPSHOT\mavenCucumberPrototype-0.0.1-SNAPSHOT.pom
  [INFO] ------------------------------------------------------------------------
  [INFO] BUILD SUCCESS
  [INFO] ------------------------------------------------------------------------
   [INFO] Total time: 3.794 s
    [INFO] Finished at: 2017-04-12T01:36:58-04:00
   [INFO] Final Memory: 17M/194M
     [INFO] ------------------------------------------------------------------------
`C:\使用 rs\PragatiChaturvedi\workspace\MavenCumberPrototype\src\test\java\com\cu cumber\mavencumberPrototype>javac RunnerTest.java java:5:错误:包cucumber.api不存在 进口cucumber.api.CucumberOptions; ^ java:6:错误:包cucumber.api.junit不存在 进口cucumber.api.junit.cucumber; ^ java:9:错误:找不到符号 @黄瓜选项( ^ 符号:类别黄瓜选项 java:8:错误:找不到符号 @RunWith(cumber.class) ^ 符号:黄瓜类 4个错误 C:\Users\PragatiChaturvedi\workspace\mavencumberprototype\src\test\java\com\ucumber\mavencumberprototype>javac steps.java steps.java:3:错误:包cucumber.api.java.en不存在 导入cucumber.api.java.en.Given; ^ steps.java:4:错误:包cucumber.api.java.en不存在 导入cumber.api.java.en.Then; ^ steps.java:5:错误:包cucumber.api.java.en不存在 导入cucumber.api.java.en.When; ^ steps.java:9:错误:找不到符号 @给定(“^这是我的第一个虚拟给定步骤$”) ^ 符号:给定的类 地点:课堂步骤 steps.java:14:错误:找不到符号 @当(“^这是我的第二个虚拟给定步骤$”) ^ 符号:上课时 地点:课堂步骤 steps.java:19:错误:找不到符号 @然后(“^这是我的第三个虚拟步骤$”) ^ 符号:那就上课吧 地点:课堂步骤
6个错误

这是一个maven项目,javac不是编译/构建项目的方式

如果我错了,请纠正我,但我假设您不了解maven


试着从C:\Users\PragatiChaturvedi\workspace\mavenCucumberPrototype运行
mvn clean install
,看看测试是否正在执行。

我在POM.XML中尝试过这个,它已经成功了

<?xml version="1.0" encoding="UTF-8"?>
<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>groupId</groupId>
    <artifactId>CucumberBasic</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>4.2.3</version>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>4.2.3</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/junit/junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

</project>

4.0.0
groupId
黄瓜碱
1.0-快照
黄瓜
黄瓜爪哇
4.2.3
黄瓜
黄瓜刺柏
4.2.3
测试
朱尼特
朱尼特
4.12
测试

您是如何运行测试的?如果是从IDE运行的,请尝试从命令行查看错误是否仍然存在。请不要使用这些详细信息的注释部分。您可以随时编辑您的问题。我相信您没有使用“maven clean verify”来运行测试。@djames:谢谢您的回答。我已在中更新了命令行输出问题。但是,我在运行上面提到的maven clean verify命令时出错。您应该了解maven。在这种情况下,请从C:\Users\Pragati Chaturvedi\workspace\MavenCumberPrototype或pom文件所在的文件夹运行“mvn clean verify”。从控制器执行时,运行mvn clean install命令时没有错误y POM所在的位置,但我在运行steps.java时遇到了相同的错误,即错误:package cucumber.api不存在运行mvn安装时没有错误这意味着您的测试已成功执行,您应该在控制台输出中看到printlns。steps.java上的javac不是您运行测试用例的方式,而是您执行测试的方式mpile这些类。如果您发现答案有用,请使用复选框将其标记为已接受。这就是StackOverflow的工作原理。我可以从您的maven输出中看到测试没有得到执行。这是因为您应该在RunnerTest.java中指定您的功能文件。它应该是features=“classpath:myFeature.feature“我做出了这一改变,但问题没有得到解决