我通过参考链接创建了一个示例struts 2项目和J单元测试用例 。
以下是我的POM文件。
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>au.com.woolworths</groupId>
<artifactId>struts_junit</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>struts_junit Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.3.4</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-junit-plugin</artifactId>
<version>2.3.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
</dependency>
</dependencies>
<build>
<finalName>struts_junit</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-toolchains-plugin
</artifactId>
<versionRange>
[1.1,)
</versionRange>
<goals>
<goal>toolchain</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.19.1</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
<configuration>
<parallel>methods</parallel>
<threadCount>10</threadCount>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
</plugins>
</build>
</project>
我能够在Eclipse中成功执行测试用例,但是在进行Maven构建期间,出现以下错误。
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.768 s
[INFO] Finished at: 2017-02-03T11:22:46+11:00
[INFO] Final Memory: 11M/168M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project struts_junit: Execution default-test of goal org.apach
e.maven.plugins:maven-surefire-plugin:2.19.1:test failed: There was an error in the forked process
[ERROR] java.lang.NoClassDefFoundError: org/junit/runner/notification/RunListener
[ERROR] at java.lang.ClassLoader.defineClass1(Native Method)
[ERROR] at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
[ERROR] at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
[ERROR] at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
[ERROR] at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
[ERROR] at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
[ERROR] at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
[ERROR] at java.security.AccessController.doPrivileged(Native Method)
[ERROR] at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
[ERROR] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[ERROR] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
[ERROR] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[ERROR] at java.lang.Class.getDeclaredConstructors0(Native Method)
[ERROR] at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
[ERROR] at java.lang.Class.getConstructor0(Class.java:3075)
[ERROR] at java.lang.Class.getConstructor(Class.java:1825)
[ERROR] at org.apache.maven.surefire.util.ReflectionUtils.getConstructor(ReflectionUtils.java:79)
[ERROR] at org.apache.maven.surefire.util.ReflectionUtils.instantiateOneArg(ReflectionUtils.java:130)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.createProviderInCurrentClassloader(ForkedBooter.java:321)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121)
[ERROR] Caused by: java.lang.ClassNotFoundException: org.junit.runner.notification.RunListener
[ERROR] at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
[ERROR] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[ERROR] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
[ERROR] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[ERROR] ... 22 more
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
有人可以建议我为什么会发生此错误以及如何解决此问题吗?
更新依赖项可以解决此问题-
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
</dependency>
至
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
如Rundoc的Javadoc中所述,该类是在版本中引入的4.0
。此外,请确保不会通过传递不同版本来解析同一工件。
我正在尝试用Java学习Selemnium。当我使用命令“MVN测试”时,我有以下错误。执行goal org.apache.maven.plugins失败:maven-surefire-plugin:3.0.0-M3:test 我尝试了command:mvn dependency::tree,并刷新了我的项目Eclipse。我试图改变版本,但没有结果。 你有什么想法吗?StackOverflow已
当我尝试在ubuntu linux(14.x)上从jenkins(作为maven项目)启动pom.xml时,我得到了以下错误。请帮我做同样的事。 [ERROR]未能在项目UI上执行goal org.apache.maven.plugin:maven-surefire-plugin:2.19.1:test(default-test)-test:执行default-test of goal org.a
我正在尝试为我的spring-boot应用程序构建一个docker映像。这是我的DockerFile: 这是我的pom.xml文件,其中有我的io.fabric8插件: 当我试图使用构建docker映像时,我得到一个错误: 无法执行目标IO.fabric8:docker-maven-plugin:0.15.3:在项目详细信息上生成(default-cli)app:执行目标IO.fabric8:do
我被这个错误弄得神魂颠倒,在我解决这个问题之前,我无法取得任何进展。 我有最新的STS(Spring Tool Source)3.7.1,专门用于Eclipse Mars 4.5.1。我删除了所有旧版本的STS,也删除了旧的.Eclipse文件,因为我希望这是一个全新的安装。我还进入了c:\Users\Tom Holmes\AppData文件夹,删除了“Spring Tool Suite”的所有痕
我需要附加诱惑力到我的cucumber(Java)测试项目。 事实上,如果我从JUnit Test-Starter启动所有测试,它们都能正确运行。 如果使用以下命令运行测试: 在Maven日志的最后,我得到了: 这就造成了这样的情况,即在mvn站点命令后无法形成倾城报告。 下面是错误的stacktrace: 下面是pom.xml文件的内容: 你能帮我拿一下这个吗?
Im试图在maven中获得一个简单有效的登录测试版本,以便稍后在jenkins服务器上运行。 问题是:每次我构建(干净安装)时,我都会收到以下错误: 我在这里乱扔头发,怎么解决这个问题?(错误不是头发)