Junit 运行单元测试时出现IntelliJ错误:无法找到或加载主类${surefireArgLine}
在IntelliJ中运行单元测试时出现以下错误: 错误:无法找到或加载主类${surefireArgLine}。 我正在使用maven,在pom.xml中我有:Junit 运行单元测试时出现IntelliJ错误:无法找到或加载主类${surefireArgLine},junit,intellij-idea,maven-surefire-plugin,Junit,Intellij Idea,Maven Surefire Plugin,在IntelliJ中运行单元测试时出现以下错误: 错误:无法找到或加载主类${surefireArgLine}。 我正在使用maven,在pom.xml中我有: <properties> ... <surefire.argLine /> </properties> <build> <plugins> <plugin> <groupId>com.my
<properties>
...
<surefire.argLine />
</properties>
<build>
<plugins>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<!--Sets the VM argument line used when unit tests are run.-->
<argLine>${surefire.argLine}</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.1.201405082137</version>
<executions>
<!--
Prepares the property pointing to the JaCoCo runtime agent which
is passed as VM argument when Maven the Surefire plugin is executed.
-->
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!--Sets the path to the file which contains the execution data.-->
<destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
<!--
Sets the name of the property containing the settings
for JaCoCo runtime agent.
-->
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
...
...
com.mysema.maven
aptmaven插件
1.1.1
过程
目标/生成的源代码/java
com.mysema.query.apt.jpa.JPAAnnotationProcessor
org.apache.maven.plugins
maven surefire插件
2.17
${surefire.argLine}
org.jacoco
jacocomaven插件
0.7.1.201405082137
单元前测试
配制剂
${project.build.directory}/coverage reports/jacoco-ut.exec
surefireArgLine
...
有人有类似的问题吗?如何设置surefireArgLine的值?我发现我必须使用 mvn-Dtest=测试循环测试
不是直接从IDE来的。我通过将surefire插件版本更改为2.10并删除
<argLine>-Xmx1024m -XX:MaxPermSize=256m ${argLine}</argLine>
-Xmx1024m-XX:MaxPermSize=256m${argLine}
来自maven surefire插件配置。相反,我创建了一个属性argLine,由surefire自动拾取
<properties>
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
</plugin>
-Xmx1024m-XX:MaxPermSize=256m
org.apache.maven.plugins
maven surefire插件
2.10
现在,我可以运行和调试单个文件和测试方法。代码覆盖率也在按预期工作。我也遇到了同样的问题,我想我找到了解决方案 简言之,您必须配置IntelliJ Maven(surefire插件)集成以实现不同的行为 这在IntelliJ 14.1.6和mvn 3.3.9中适用
Preferences->Build,Execution,Deployment->Build Tools->Maven->Running Tests
适用于IntelliJ 2019及以上
Settings->Build,Execution,Deployment->Build Tools->Maven->Running Tests
取消选中
argLine
正在查找此项目,并在中找到此项目“修复”
基本上,将JacoCargline变量名称定义为空项目属性。然后在surefire配置中使用@{jacocorgline}而不是美元前缀。更新pom.xml解决了我的问题
<argLine>${surefire.argLine}</argLine>
${surefire.argLine}
在pom.xml中完成插件信息
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<parallel>classes</parallel>
<threadCount>10</threadCount>
<workingDirectory>${project.build.directory}</workingDirectory>
<jvm>${env.JDK1_8_HOME}\bin\java</jvm>
<argLine>${surefire.argLine}</argLine>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit4</artifactId>
<version>2.18.1</version>
</dependency>
</dependencies>
</plugin> -->
org.apache.maven.plugins
maven surefire插件
2.18.1
班级
10
${project.build.directory}
${env.JDK1_8_HOME}\bin\java
${surefire.argLine}
org.apache.maven.surefire
surefire-junit4
2.18.1
-->
您是否找到了另一种解决方案?我需要从IDE运行它才能使用调试模式。不幸的是,我还没有找到其他解决方案。@LisaMM您可以调试测试,而无需在IDE中运行测试。只需在命令行上使用mvnDebug启动测试。然后使用您喜爱的IDE连接到命令行进程。谷歌在您最喜欢的IDE中“远程调试”。“jah”(有200多个ups)提出的BlueLettuce16解决方案更好,请您相应地标记一下好吗?感谢您在2016年初提出了同样的问题;)在Intellij 2016中:设置
->构建、执行、,部署
->构建工具
->Maven
->运行测试
谢谢…当尝试对构建进行更改并确保其不会对开发人员产生副作用时,找到这样一篇文章的机会有多大…上帝保佑stackoverflow。您好,2018年:)这是一个宝贵的解决方案。非常感谢。在Intellij 2018中:File>Settings>Build,Execution,Deployment>Build Tools>Maven>Running Tests
这也适用于Intellij。这个选项是正确的。