我正在尝试执行Cucumber测试,但得到:“java:包io. cubble.junit不存在”

mnemlml8  于 2023-02-07  发布在  Java
关注(0)|答案(1)|浏览(155)

下面是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.0http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>SeleniumProject</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
    <dependency>
        <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>7.2.3</version>
            <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>7.2.3</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.141.59</version>
     </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
           <configuration>
            <source>1.8</source>
            <target>1.8</target>
                <includes>
                    <include>src/test/java</include>
                </includes>
          </configuration>
       </plugin>
    </plugins>
</build>
</project>

下面是测试运行程序:

package runner; 

import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith; 

@RunWith(Cucumber.class)
@CucumberOptions( 
        plugin = {},
        features = "src/test/resources/features",
        tags = "~@ignore",
        glue = {"steps"}
)

public class RunCucumberTest {
}

运行后,我得到:

java: package io.cucumber.junit does not exist
java: package org.junit.runner does not exist

java: cannot find symbol
  symbol: class RunWith

java: cannot find symbol
  symbol: class CucumberOptions

我该怎么解决这个问题?
我试过了

mvn clean install

一切似乎都很顺利

T E S T S

跑步跑步者。运行CucumberTest?????????????????????????????????????????????????????????????????????????????????????????????????????????????????在https://reports.cucumber.io上与您的工作组共享您的CucumberReport?????????????????????????????????????????????????????????????????????????????????????????????????????????????源代码/测试/资源/www.example.com: cucumber .发布.启用=真??源代码/测试/资源/www.example.com: cucumber .发布.启用=真??环境变量:cucumber.properties @CucumberOptions(publish = true)????有关详细信息,请访问https://cucumber.io/docs/cucumber/environment-variables/????使用以下选项之一禁用此消息:junit-platform.properties测试运行:0,失败:0,错误:0,跳过:0,经过时间:0.396秒cucumber.properties: cucumber.publish.quiet=true ? ? src/test/resources/junit-platform.properties: cucumber.publish.quiet=true ? ????????????????????????????????????????????????????????????????????????????????????? Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.396 sec
结果:
测试运行:0,失败:0,错误:0,跳过:0

x9ybnkn6

x9ybnkn61#

考虑在pom.xml中包含junit依赖项

<dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

相关问题