Java:包cucumber.api.junit 不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42924356/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java: package cucumber.api.junit does not exist
提问by Chai
I've been trying to get this to work.
我一直在努力让它发挥作用。
I would like set up a test runner class like so
我想建立一个测试运行器类,像这样
However I get this error:
但是我收到这个错误:
Error:(3, 26) java: package cucumber.api.junit does not exist
Error:(10, 10) java: cannot find symbol
symbol: class Cucumber
错误:(3, 26) java: 包cucumber.api.junit 不存在
错误:(10, 10) java: 找不到符号
symbol: class Cucumber
The class looks like:
这个类看起来像:
package nl.prvgld.sigma.aanvraagtitels.testutil;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
public class RunFeature {
}
Pom.xml looks like:
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/maven-v4_0_0.xsd">
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<modelVersion>4.0.0</modelVersion>
<groupId>nl.prvgld.sigma.aanvraagtitels</groupId>
<artifactId>Aanvraagtitels</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>Aanvraagtitels</name>
<url>http://maven.apache.org</url>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java8</artifactId>
<version>1.2.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-core -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-junit -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.1.0.jre8</version>
</dependency>
<dependency>
<groupId>com.smartbear.readyapi.testserver.cucumber</groupId>
<artifactId>testserver-cucumber-core</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
All classes are somewhere under the Test folder. I've been lookin at some related questions here and tried the solutions like removing test from Pom, and making sure I have junit, cucumber-junit, cucumber-java8 and cucumber-core in the Pom.
所有类都位于 Test 文件夹下的某个位置。我一直在这里查看一些相关问题,并尝试了解决方案,例如从 Pom 中删除测试,并确保我在 Pom 中有junit、cucumber-junit、cucumber-java8 和cucumber-core。
I am using Intellij.
我正在使用 Intellij。
Any help in the right direction is highly appreciated!
任何在正确方向上的帮助都非常感谢!
Cheers!
干杯!
回答by Higor Haider
I don't know if you already resolved your issue but you can quickly fix it by removing the scope tags from your pom.xml file. Do this action for all dependencies that you are facing issues and should work fine.
我不知道您是否已经解决了您的问题,但您可以通过从 pom.xml 文件中删除范围标记来快速修复它。对您遇到问题的所有依赖项执行此操作,并且应该可以正常工作。
Cheers, HH
干杯,HH
回答by Thomas Sundberg
By inspection, everything looks good. But obviously, it doesn't work as you expect.
通过检查,一切看起来都很好。但很明显,它不像你期望的那样工作。
Do you get the same error when compiling with IDEA and compiling with Maven?
用IDEA编译和用Maven编译的时候有没有同样的错误?
To get started, I would clone a getting started project from the Cucumber team and get it working. It is much easier to later extend it to contain the things you need. Clone https://github.com/cucumber/cucumber-java-skeletonand build it using Maven with
首先,我会从 Cucumber 团队克隆一个入门项目并使其工作。以后扩展它以包含您需要的东西要容易得多。克隆https://github.com/cucumber/cucumber-java-skeleton并使用 Maven 构建它
mvn clean install
It is expected to work out of the box.
预计它可以开箱即用。
With a working solution, take small steps toward the project you actually would like to have.
有了可行的解决方案,朝着您真正想要的项目迈出一小步。