运行单元测试时出现IntelliJ错误:无法找到或加载主类$ {surefireArgLine}

Blu*_*e16 61 junit intellij-idea maven-surefire-plugin

在IntelliJ中运行单元测试时出现以下错误:错误:无法找到或加载主类$ {surefireArgLine}.我正在使用maven,在pom.xml中我有:

<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>
   ...
Run Code Online (Sandbox Code Playgroud)

有没有人有类似的问题?如何设置surefireArgLine的值?

jah*_*jah 204

我有同样的问题,我想我在vertx-issue跟踪器上找到了解决方案.

简而言之,您必须配置IntelliJ Maven(surefire插件)集成以使其表现不同.

这样做是通过: Preferences -> Build,Execution,Deployment -> Build Tools -> Maven -> Running Tests

取消选中 argLine

这适用于IntelliJ 14.1.6和mvn 3.3.9

  • 在Intellij 2016:`设置` - >`构建,执行,部署` - >`构建工具` - >`Maven` - >`运行测试 (16认同)
  • 感谢2016年初的同样问题;) (5认同)
  • 2017年仍有这个问题,解决方案有效. (3认同)
  • 嗨来自2018年:)这是一个宝贵的解决方案.非常感谢你. (3认同)
  • 谢谢...当尝试对构建进行更改并确保它对开发人员没有副作用时,有什么机会找到这样的帖子...上帝保佑stackoverflow. (2认同)
  • 在Intellij 2018中:`文件&gt;设置&gt;构建,执行,部署&gt;构建工具&gt; Maven&gt;运行测试` (2认同)

tak*_*shi 8

通过将surefire-plugin版本更改为2.10并删除,我能够在Netbeans中修复此错误

<argLine>-Xmx1024m -XX:MaxPermSize=256m ${argLine}</argLine>
Run Code Online (Sandbox Code Playgroud)

来自maven-surefire-plugin配置.相反,我创建了一个属性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>
Run Code Online (Sandbox Code Playgroud)

现在,我可以运行和调试单个文件和测试方法.代码覆盖率正如预期的那样工作.