我正在使用声纳2.6和maven 3
我使用默认的corbetura插件来代码覆盖我的项目,但它总是显示0%的覆盖率,虽然我已经使用junit-4.9b2.jar编写了junit测试用例
这是我的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>
<groupId>com.niit.karan</groupId>
<artifactId>DataBlast</artifactId>
<name>DataBlast</name>
<version>1.0</version>
<build>
<sourceDirectory>src</sourceDirectory>
<outputDirectory>bin</outputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<excludes>
<exclude>**/*.*</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.3</version>
<configuration>
<forkMode>once</forkMode>
<instrumentation>
<ignores>
<ignore>com.example.boringcode.*</ignore>
</ignores>
<excludes>
<exclude>com/example/dullcode/**/*.class</exclude>
<exclude>com/example/**/*Test.class</exclude>
</excludes>
</instrumentation>
</configuration>
<executions>
<execution>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>2.0-beta-2</version>
<configuration>
<timeout>3600000</timeout>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<sonar.dynamicAnalysis>true</sonar.dynamicAnalysis>
</properties>
</project>
这是我为了检查插件而编写的测试用例:
package test;
import junit.framework.TestCase;
public class TestCalc extends TestCase{
Calc calc = new Calc();
public void testSum(){
assertTrue(3 == calc.sum(1, 2));
assertTrue(4 == calc.sum(2, 2));
}
}
有人请帮忙考虑我是声纳的新用户..提前致谢
答案 0 :(得分:2)
maven-compiler-plugin配置为跳过所有源代码,包括测试。删除&lt;排除&gt;插件配置会话,以便Maven正常工作,编译源代码和测试。
答案 1 :(得分:1)
之前我遇到过同样的问题。在我的情况下,它因为Surefire插件属性设置错误:
Maven项目始终在构建生命周期的测试阶段使用Surefire插件来执行单元测试。如果有Surefire的测试配置,请检查您的pom.xml。将the设置为“false”,如果设置为“true”,Sonar将不会编译并运行您的单元测试用例,那么总是有0%的覆盖率:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<includes>
<include>**/*Test*.java</include>
</includes>
<parallel>methods</parallel>
<threadCount>10</threadCount>
<testFailureIgnore>true</testFailureIgnore>
<skipTests>false</skipTests>
<skip>false</skip>
</configuration>
</plugin>
希望它可以帮到你。