java 在< package>pom.xml中添加cucumber-junit-platform-engine依赖项后,Intellij mvn安装在测试编译期间抱怨“无法访问“

fdbelqdn  于 2022-10-30  发布在  Java
关注(0)|答案(2)|浏览(159)

我计划在Maven中使用Cucumber Test和Junit5。因此我按照cucumber安装了不同的Maven依赖项。我添加了一个runner类来执行Cucumber测试

package pirate;
import org.junit.platform.suite.api.ConfigurationParameter;
import org.junit.platform.suite.api.IncludeEngines;
import org.junit.platform.suite.api.SelectClasspathResource;
import org.junit.platform.suite.api.Suite;

import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;

@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("pirate")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "pirate")
public class Runner {}

我还在resources文件夹下创建了一个名为pirate的新文件夹,并将所有.feature文件移到这个新文件夹中。但是当我执行mvn clean install时,命令在testCompile时失败:

似乎编译器无法读取包名?下面是我的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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.example</groupId>
  <artifactId>onetwothree</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

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

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <build>
    <testSourceDirectory>src/test/java</testSourceDirectory>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
          <source>11</source>
          <target>11</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0-M5</version>
        <configuration>
          <properties>
            <configurationParameters>
              cucumber.junit-platform.naming-strategy=long
            </configurationParameters>
          </properties>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter</artifactId>
      <version>5.9.0</version>
    </dependency>
    <dependency>
      <groupId>io.cucumber</groupId>
      <artifactId>cucumber-java</artifactId>
      <version>7.8.1</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>io.cucumber</groupId>
      <artifactId>cucumber-junit-platform-engine</artifactId>
      <version>7.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.platform</groupId>
      <artifactId>junit-platform-suite</artifactId>
      <version>1.9.0</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

我的项目结构是:

但是如果我注解掉pom.xml中的cucumber-junit-platform-engine依赖项,错误就消失了,但是它不会运行cubber测试。
不确定是否相关,但其中一条错误消息如下:

[ERROR] error reading /Users/xx/.m2/repository/org/junit/platform/junit-platform-engine/1.9.1/junit-platform-engine-1.9.1.jar; zip file is empty
[ERROR] /Users/xx/Desktop/zz/src/test/java/pirate/Runner.java:[1,1] cannot access pirate
  ZipException opening "junit-platform-engine-1.9.1.jar": zip END header not found
c7rzv4ha

c7rzv4ha1#

您是否尝试了与cucumber-junit-platform-engine依赖项测试不同的范围?

zu0ti5jz

zu0ti5jz2#

Maven : error in opening zip file when running maven的最大值
按照以下过程修复“无法访问“问题。

相关问题