黄瓜框架中的ClassNotFoundException



我正在使用Cucumber框架进行移动应用程序测试。在pom.xml中,我已经给出了下面的插件来运行TestClass.java -它有用于上传最新APK版本的应用程序的代码。Main方法存在于这个TestClass中。我需要在实际测试执行之前运行这个。所以我使用了exec插件。如果我运行pom.xml——>MVN清洁测试。ClassNotFoundExpection总是与pom.xml一起抛出,但单个类运行良好。

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$1.run(ExecJavaMojo.java:246)
at java.lang.Thread.run(Thread.java:748)

我还尝试在测试编译后更改阶段。我仍然得到相同的错误。谁来帮帮我。

根据exec-maven-plugin文档,执行的默认依赖范围是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>

最新更新