运行myfeature.feature时出现JUNIT错误,因为黄瓜JVM测试> potes.cucumberjvm.test.RunCucumberTest>初始化错误

Test Data :-

1)Java java版本“1.8.0_121”Java(TM)SE运行时环境(版本1.8.0_121-b13)Java HotSpot(TM)64位服务器VM(版本25.121-b13,混合模式)

2)用于Java开发人员的Eclipse Eclipse 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");
}
}

RunnerTest.java

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>

Stack Trace :-

java.lang.TypeNotPresentException: Type cucumber.junit.Cucumber not present
at sun.reflect.annotation.TypeNotPresentExceptionProxy.generateException(TypeNotPresentExceptionProxy.java:46)
at sun.reflect.annotation.AnnotationInvocationHandler.invoke(AnnotationInvocationHandler.java:84)
at com.sun.proxy.$Proxy2.value(Unknown Source)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:84)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:70)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.ClassNotFoundException: cucumber.junit.Cucumber
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:114)
at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:125)
at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
at sun.reflect.annotation.AnnotationParser.parseSig(AnnotationParser.java:439)
at sun.reflect.annotation.AnnotationParser.parseClassValue(AnnotationParser.java:420)
at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:349)
at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:286)
at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120)
at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72)
at java.lang.Class.createAnnotationData(Class.java:3521)
at java.lang.Class.annotationData(Class.java:3510)
at java.lang.Class.getAnnotation(Class.java:3415)
at org.junit.internal.builders.IgnoredBuilder.runnerForClass(IgnoredBuilder.java:10)
... 11 more

命令行输出: -

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] ------------------------------------------------------------------------

http://cwiki.apache.org/confluence/display/MAVEN/MissingProjectException`C:\使用rs \ PragatiChaturvedi \ workspace \ mavenCucumberPrototype \ src \ test \ java \ com \ cu cumber \ mavenCucumberPrototype> javac RunnerTest.java RunnerTest.java:5:错误:package cucumber.api不存在import cucumber.api .CucumberOptions; ^ RunnerTest.java:6:错误:package cucumber.api.junit不存在import cucumber.api.junit.Cucumber; ^ RunnerTest.java:9:错误:找不到符号@CucumberOptions(^符号:类CucumberOptions RunnerTest.java:8:错误:找不到符号@RunWith(Cucumber.class)^符号:类Cucumber 4错误C:\ Users \ PragatiChaturvedi \ workspace \ mavenCucumberPrototype \ src \ test \ java \ com \ ucumber \ mavenCucumberPrototype> javac steps.java steps.java:3:error:package cucumber.api.java.en不存在import cucumber.api.java.en . 给出; ^ steps.java:4:错误:package cucumber.api.java.en不存在导入cucumber.api.java.en.Then; ^ steps.java:5:错误:package cucumber.api.java.en不存在导入cucumber.api.java.en.When; ^ steps.java:9:错误:找不到符号@Given("^This is my first dummy given step$")^符号:class给定位置:类步骤steps.java:14:错误:找不到符号@When("^This is my second dummy given step$")^符号:class当位置:类步骤steps.java:19:错误:找不到符号@Then("^This is my third dummy given step$")^符号:class然后位置:类步骤6错误

回答(1)

3 years ago

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

如果我错了,请纠正我,但我会假设你不知道maven . 这些是关于maven的一些教程 .

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