【发布时间】:2017-09-07 15:50:29
【问题描述】:
测试数据:-
1)Java java 版本 "1.8.0_121" Java(TM) SE 运行时环境 (build 1.8.0_121-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, 混合模式)
2) Eclipse Eclipse IDE for Java Developers 版本:Neon.2 Release (4.6.2) Build id:20161208-0600
3)操作系统 Microsoft Windows 10 家庭版 - 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>
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:错误:包 cucumber.api 不存在 导入 cucumber.api.CucumberOptions; ^ RunnerTest.java:6:错误:包 cucumber.api.junit 不存在 进口黄瓜.api.junit.黄瓜; ^ RunnerTest.java:9:错误:找不到符号 @黄瓜选项( ^ 符号:类 CucumberOptions RunnerTest.java:8:错误:找不到符号 @RunWith(Cucumber.class) ^ 符号:黄瓜类 4 个错误 C:\Users\PragatiChaturvedi\workspace\mavenCucumberPrototype\src\test\java\com\ ucumber\mavenCucumberPrototype>javac steps.java steps.java:3:错误:包 cucumber.api.java.en 不存在 进口黄瓜.api.java.en.Given; ^ steps.java:4:错误:包 cucumber.api.java.en 不存在 导入黄瓜.api.java.en.然后; ^ steps.java:5:错误:包 cucumber.api.java.en 不存在 导入 cucumber.api.java.en.When; ^ steps.java:9:错误:找不到符号 @Given("^This is my first dummy given step$") ^ 符号:给定的类 地点:课堂台阶 steps.java:14:错误:找不到符号 @When("^This is my second dummy given step$") ^ 符号:类当 地点:课堂台阶 steps.java:19:错误:找不到符号 @Then("^这是我给定步骤$的第三个假人") ^ 符号:类然后 地点:课堂台阶 6 个错误
【问题讨论】:
-
你是如何运行测试的?如果是你的IDE,请从命令行试试看错误是否仍然存在
-
请不要在评论区使用这些细节。您可以随时编辑您的问题。我相信您没有使用“maven clean verify”来运行测试。
-
@djames:感谢您的回复。我已经更新了问题中的命令行输出。但是,如上所述,我在运行 maven clean verify' 命令时遇到错误
-
你应该了解 maven。在这种情况下,从 C:\Users\Pragati Chaturvedi\workspace\mavenCucumberPrototype 或您的 pom 文件所在的文件夹运行“mvn clean verify”。
标签: java maven junit cucumber cucumber-junit