黄瓜框架中的 ClassNotFoundException

ClassNotFoundException in cucumber framework

我正在使用 Cucumber 框架进行移动应用程序测试。在 pom.xml 中,我已将下面的插件提供给 运行 TestClass.java - 它具有用于上传应用程序最新 APK 版本的代码。 Main 方法存在于此 TestClass 中。在实际测试执行之前,我需要这个 运行 。所以我使用了 exec 插件。如果我是 运行 pom.xml --> mvn clean test,我会收到此错误。 ClassNotFoundExpection 总是抛出 pom.xml,但个别 class 运行 是完美的。

pom.xml:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>3.0.0</version>
       <executions>
    <execution>
            <id>installAPK</id>
            <phase>generate-test-sources</phase>
            <goals>
            <goal>java</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <includePluginDependencies>true</includePluginDependencies>
        <mainClass>org.com.package1.TestClass</mainClass>
    </configuration>
</plugin>

控制台错误:

java.lang.ClassNotFoundException: org.com.package1.TestClass
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
    at org.codehaus.mojo.exec.ExecJavaMojo.run(ExecJavaMojo.java:246)
    at java.lang.Thread.run(Thread.java:748)

我也试过在测试编译后改变阶段。我仍然遇到同样的错误。有人请帮助。

根据exec-maven-plugin documentation,执行的默认依赖范围是runtime。如果 TestClass 是测试源的一部分,请使用以下配置将其更改为 test

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <version>3.0.0</version>
  <executions>
    ...
  </executions>
  <configuration>
    ...
    <classpathScope>test</classpathScope>
  </configuration>
</plugin>