如何使FlexUnit的代码覆盖与Sonar一起使用?

时间:2012-09-10 14:30:51

标签: maven sonarqube flexunit flexunit4

场合

我正在尝试Sonar使用Flex-Mojos显示FlexUnit从Maven构建作业生成的代码覆盖率报告但是我没有运气 - 我得到的只是一个令人沮丧的“ - ”。


构建输出

结果是仪表板始终显示此信息(左列): Sonar project dashboard (不,单元测试不会运行超过90分钟而是16秒;不知道这里有什么关闭)

Sonar相关的控制台输出如下: Maven console output 所以一切似乎都运行正常(除了Cobertura之外没有任何文件未找到的错误,我似乎无法以任何方式摆脱它,没有解析异常等)。


构建设置

用于构建项目的pom.xml如下所示:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>foo</groupId>
        <artifactId>parent</artifactId>
        <version>1.0.3</version>
    </parent>
    <groupId>foo</groupId>
    <artifactId>bar</artifactId>
    <version>0.1.0-SNAPSHOT</version>
    <packaging>swc</packaging>
    <name>Bar</name>
    <dependencies>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito</artifactId>
            <version>1.4M5</version>
            <type>swc</type>
            <scope>external</scope>
        </dependency>
        <dependency>
            <groupId>com.adobe.flexunit</groupId>
            <artifactId>flexunit</artifactId>
            <version>4.1.0-8</version>
            <classifier>flex</classifier>
            <type>swc</type>
            <scope>external</scope>
        </dependency>
    </dependencies>
    <build>
        <testSourceDirectory>src/test/flash</testSourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.sonatype.flexmojos</groupId>
                <artifactId>flexmojos-maven-plugin</artifactId>
                <version>4.2-beta</version>
                <configuration>
                    <coverage>true</coverage>
                    <debug>false</debug>
                    <optimize>true</optimize>
                    <omitTraceStatements>true</omitTraceStatements>
                    <verboseStacktraces>false</verboseStacktraces>
                    <defines>
                        <property>
                            <name>CONFIG::BUILD</name>
                            <value>"${project.version}"</value>
                        </property>
                    </defines>
                </configuration>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>asdoc</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>${project.build.directory}/asdoc/tempdita</directory>
                <targetPath>docs</targetPath>
                <includes>
                    <include>**/*.xml</include>
                </includes>
                <excludes>
                    <exclude>ASDoc_Config.xml</exclude>
                    <exclude>overviews.xml</exclude>
                </excludes>
            </resource>
        </resources>
    </build>
    <properties>
        <sonar.language>flex</sonar.language>
        <sonar.sources>src/main/flash</sonar.sources>
        <sonar.tests>src/test/flash</sonar.tests>
        <sonar.surefire.reportsPath>target/surefire-reports</sonar.surefire.reportsPath>
    </properties>
</project>

我尝试了几种方法来运行声纳:

  1. dynamicAnalysis=reuseReports + mvn clean install + mvn sonar:sonar

  2. dynamicAnalysis=true + mvn clean install sonar:sonar -Dmaven.test.failure.ignore=true

  3. dynamicAnalysis=true + mvn clean install -DskipTests=true + mvn sonar:sonar(&lt; - 不起作用:出于某种原因,在这种情况下,单元测试在执行期间无法使用NullPointerException运行Flex-Mojos的test-run目标。


  4. 有没有办法在Sonar仪表板中显示覆盖率结果?我需要额外的插件(Emma,Clover,无论如何)来获得标准Surefire报告的报道吗?是否存在阻止此工作的已知问题?我做错了吗?


    更新

    我尝试用Sonar-Runner运行Sonar。有趣的是,仪表板然后完全删除了代码覆盖小部件。检查跑步者的控制台输出显示跑步者没有执行FlexSurefireSensorsonar:sonar Maven目标所做的事情):

    Console output for sonar-runner

    sonar-project.properties文件包含:

    sonar.projectKey=foo:bar
    sonar.projectName=Bar
    sonar.projectVersion=0.1.0-SNAPSHOT
    
    sonar.language=flex
    sources=src/main/flash
    tests=src/test/flash
    
    sonar.dynamicAnalysis=reuseReports
    sonar.surefire.reportsPath=target/surefire-reports
    

    我正在使用mvn clean install然后sonar-runner运行它。

3 个答案:

答案 0 :(得分:2)

要获得代码覆盖率,您需要添加以下属性:

<sonar.cobertura.reportPath>target/site/coverage-cobertura/coverage.xml</sonar.cobertura.reportPath>

(或覆盖文件的路径)。

这在the plugin home page上有记录。

答案 1 :(得分:1)

我认为您在POM中缺少的属性是 sonar.dynamicAnalysis

<properties>
    ..
    <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
    <sonar.surefire.reportsPath>target/surefire-reports</sonar.surefire.reportsPath>
</properties>

Flex plugin documentation介绍了如何启用单元测试和代码覆盖率报告。它还建议使用Java Runner,但它应该在功能上类似于Maven插件启动器。

答案 2 :(得分:-3)

在尝试了一些更多不同的设置和属性组合之后,我已经正式放弃了获得代码覆盖率。出于某种原因,我无法让它按预期工作。 &LT;。&LT;

然而,即使没有直接包含代码覆盖,声纳报告对我们的目的来说也“足够好”。让它工作真的很不错,但这不是一个交易破坏者。

相关问题