首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >maven-surefire和tycho-surefire之间的行为不一致,jacoco不会生成报告

maven-surefire和tycho-surefire之间的行为不一致,jacoco不会生成报告
EN

Stack Overflow用户
提问于 2020-10-02 20:06:20
回答 2查看 284关注 0票数 1

我正在为一个项目创建一个pom,并向其中添加测试用例。该项目是一个eclipse插件。

使用tycho编译项目工作得很好,唯一的问题是在测试期间:如果我同时运行maven-surefire-plugin测试和tycho-surefire-plugin-test,前者会按预期执行所有测试,而后者会给出以下错误:

代码语言:javascript
复制
Execution test of goal org.eclipse.tycho:tycho-surefire-plugin:1.7.0:test failed: Tycho build extension not configured for MavenProject

我完全可以将<skipTests>true</skipTests>添加到tycho-surefire-plugin中,同时保持maven-surefire-plugin打开;问题是这样的,jacoco拒绝创建覆盖站点,并显示以下(非错误)消息:

代码语言:javascript
复制
Skipping JaCoCo execution due to missing execution data file.

我试图寻找两者的解决方案,但我找到的任何解决方案的组合都不会让我有一个有效的覆盖网站。Maven真的让我很困惑,特别是tycho在身边,所以我会在实际修复的基础上考虑任何解释。

这是我的pom:

代码语言:javascript
复制
<?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>mygroupid</groupId>
    <artifactId>myartifactid</artifactId>
    <name>myname</name>
    <packaging>eclipse-test-plugin</packaging>
    
    <properties>
        <tycho-version>1.7.0</tycho-version>
    </properties>

    <parent>
        <groupId>parentgroupid</groupId>
        <artifactId>parent</artifactId>
        <version>0.9.5</version>
    </parent>
    
    <dependencies>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.6.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.6.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.8.5</version>
        </dependency>
        
        <dependency>
            <groupId>javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.12.1.GA</version>
        </dependency>
    </dependencies>

    <build>
        <testSourceDirectory>src/test/java/</testSourceDirectory>
        <plugins>
            

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.12.4</version>
                
                <configuration>
                </configuration>

                <executions>
                    <execution>
                        <id>test</id>
                        <phase>test</phase>
                        <configuration>
                            <includes>
                                <include>**/Test_*.java</include>
                            </includes>
                        </configuration>
                        <goals>
                            <goal>test</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-surefire-plugin</artifactId>
                <version>${tycho-version}</version>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
                <executions>
                    <execution>
                        <id>test</id>
                        <phase>test</phase>
                        <configuration>
                            <includes>
                                <include>**/Test_*.java</include>
                            </includes>
                        </configuration>
                        <goals>
                            <goal>test</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.5</version>
                <configuration>
                    <output>file</output>
                    <append>true</append>
                    <includes>
                        <include>**/path_to_source/**/*</include>
                    </includes>
                </configuration>
                <executions>
                    <execution>
                        <id>jacoco-initialize</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>jacoco-site</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
         
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <executions>
                    <execution>
                        <id>compiletests</id>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

这是我的父母pom:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>parentgroupid</groupId>
    <artifactId>parent</artifactId>
    <version>0.9.5</version>
    <packaging>pom</packaging>
    <modules>
        <module>moduleid</module>
    </modules>

    <properties>
        <tycho-version>1.7.0</tycho-version>
    </properties>

    <repositories>
     <repository>
         <id>eclipse-2020-06</id>
         <layout>p2</layout>
         <url>http://download.eclipse.org/releases/2020-06</url>
     </repository>
    </repositories>

    <build>
        <plugins>
            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-maven-plugin</artifactId>
                <version>${tycho-version}</version>
                <extensions>true</extensions>
                
                <configuration>
                    <includeAllDependencies>true</includeAllDependencies>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>
EN

回答 2

Stack Overflow用户

发布于 2020-10-05 09:18:29

当然,由于您使用的是非常旧的Surefire版本2.12.4,所以不会有任何JaCoCo的测试结果。此版本不是为JUnit5创建的。使用最新版本的3.0.0-M5并查看tutorial

如果你想要有很小的POM,删除依赖junit-jupiter-engine,因为你不需要在你的测试代码中访问JUnit内部。Surefire将在测试运行时之前不久下载它。

票数 1
EN

Stack Overflow用户

发布于 2020-10-11 02:09:29

您的POM有几个错误。让我们从根本原因开始,然后从高到低依次列出其他优先级。

所有的问题是,Surefire并不知道JaCoCo。您必须以这种方式告诉“他”(参见jacoco.agent),这将“连接”两者。请阅读JaCoCo项目中的文档:

代码语言:javascript
复制
<properties>
  <jvm.args.tests>-Xmx2048m -Xms1024m -XX:SoftRefLRUPolicyMSPerMB=50 -Djava.awt.headless=true -Djdk.net.URLClassPath.disableClassPathURLCheck=true</jvm.args.tests>
<properties>
...
      <artifactId>maven-surefire-plugin</artifactId>
      <configuration>
        <argLine>${jvm.args.tests} ${jacoco.agent}</argLine>
      </configuration>
...

下一个错误是你使用插件的方式。插件jacoco-maven-plugin只能在插件部分使用。问题是,您还可以在dependencies部分使用它。您不希望将其放在类路径中。property jacoco.agent的工作是只将jacoco代理放在测试类上,但是JaCoCo插件必须在Surefire插件之前启动。

我不理解的下一件事是编译器的配置。你为什么会有这个?

代码语言:javascript
复制
             <executions>
                <execution>
                    <id>compiletests</id>
                    <phase>test-compile</phase>
                    <goals>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>

我有第二个关于包装的问题。我从来没见过这个。这不是一个标准的包装。

代码语言:javascript
复制
<packaging>eclipse-test-plugin</packaging>

Eclipse插件是否有任何特殊的二进制形式的归档文件?

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64171264

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档