首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >单元测试会失败,只有三叶草3.1.8的Null指针例外,但是所有的三叶草都会通过清理。

单元测试会失败,只有三叶草3.1.8的Null指针例外,但是所有的三叶草都会通过清理。
EN

Stack Overflow用户
提问于 2014-12-24 08:14:28
回答 1查看 1.3K关注 0票数 0

我们的项目是一个多模块maven项目,并使用clover2: to生成仪器化的fat jar。我们使用命令行中的插装jar评估功能测试代码覆盖率,下面提到的所有步骤如下:

  1. mvn清洁安装
  2. mvn -P仪器仪表柜2:仪器
  3. 运行功能测试
  4. mvn -P仪器仪表柜2:聚合
  5. mvn -P仪器仪表柜2:三叶草站点

所有单元测试都通过了三叶草4.0.2,但是当使用三叶草版本3.1.8时,它们在NPE中失败了。我们想使用旧版本,因为我们有商业许可证,而不是更新的版本。帮帮忙吧。

我不能分享这些日志,因为这可能会冒犯我的组织政策。分享节选

代码语言:javascript
复制
Tests run: 6, Failures: 6, Errors: 0, Skipped: 0, Time elapsed: 0 sec <<< FAILURE!
com.***.*.*.*.*.drools.*.*************UnitTest.testKnowledgeAgentInitialization() Time elapsed: 0 sec <<< FAILURE!
java.lang.NullPointerException
at com.***.*.*.*.*.drools.*.*************UnitTest.testKnowledgeAgentInitialization(*************UnitTest.java:149)

Parent POM for clover:
<profiles>
    <profile>
        <id>instrumentation</id>
        <activation>
            <property>
                <name>instrumentation</name>
            </property>
        </activation>
        <dependencies>
        <dependency>
                <groupId>com.atlassian.clover</groupId>
                <artifactId>clover</artifactId>
                <version>${version.clover}</version>
            </dependency>
        </dependencies>
        <build>
        <plugins>
            <plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>maven-clover2-plugin</artifactId>
                <version>${version.clover}</version>
                <configuration>
                    <license>${clover.license}</license>
                    <includesTestSourceRoots>false</includesTestSourceRoots>
                </configuration>
             <executions>
                    <execution>
                        <id>site</id>
                        <phase>pre-site</phase>
                        <goals>
                            <goal>aggregate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        </build>
    </profile>

We are using Surefire to run Unit tests
    <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.14.1</version>
                <configuration>
                   <includes>
                        <include>**/*UnitTest.java</include>
                    </includes>
                </configuration>
                <executions>
                    <execution>
                        <phase>test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <testNGArtifactName>none:none</testNGArtifactName>
                            <reportsDirectory>${project.build.directory}/surefire-reports/testng</reportsDirectory>
                        </configuration>
                    </execution>
                    <execution>
                        <id>test-testng</id>
                        <phase>test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <junitArtifactName>none:none</junitArtifactName>
                            <reportsDirectory>${project.build.directory}/surefire-reports/junit</reportsDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

从日志中添加额外的堆栈,尽管它并没有提供太多的信息

运行com..air.supply...drools.ruleengine.ApplyQueryValueThrottleEngineUnitTest测试运行: 4,失败: 4,错误: 0,跳过: 0,运行时间: 0.27秒,<<<失败!com..air.supply...drools.ruleengine.ApplyQueryValueThrottleEngineUnitTest.testKnowledgeAgentInitialization()时间过去了: 0.002秒<<<失败!com..air.supply..*.drools.ruleengine.ApplyQueryValueThrottleEngineUnitTest.testKnowledgeAgentInitialization(ApplyQueryValueThrottleEngineUnitTest.java:145)的java.lang.NullPointerException

com..air.supply...drools.ruleengine.ApplyQueryValueThrottleEngineUnitTest.testNoM_hingRule()时间过去了: 0.266秒<<<失败!com..air.supply...drools.ruleengine.ApplyQueryValueThrottleEngineUnitTest.testNoM_hingRule(ApplyQueryValueThrottleEngineUnitTest.java:124)的java.lang.NullPointerException

com..air.supply...drools.ruleengine.ApplyQueryValueThrottleEngineUnitTest.testM_hingRule()时间过去了:0秒<<<失败!com..air.supply...drools.ruleengine.ApplyQueryValueThrottleEngineUnitTest.testM_hingRule(ApplyQueryValueThrottleEngineUnitTest.java:135)的java.lang.NullPointerException

EN

回答 1

Stack Overflow用户

发布于 2015-01-21 11:57:50

正如三叶草4.0发行说明中所述,Clover 4.x与Clow3.x是二进制不兼容的。因此,您必须确保您不使用Clover 3.x来测试代码,同时在运行时提供Clove4.xJAR(反之亦然)。

特别是,确保您的构建工作区和~/.m2本地缓存都不包含由错误的三叶草版本检测的JAR文件--这是以前构建的剩余物。

在您的工作区中运行'mvn干净‘。从~/.m2中删除所有‘*-trver.jar’文件。如果您使用的是“clover2:setup”和Maven的“安装”目标,也要删除JAR文件,其中没有包含仪器化代码的名称中的“-clover”后缀(如何识别JAR是否包含仪器化代码?它的名字中将包含“$__CLR”的$__CLR文件)。

另见:https://confluence.atlassian.com/display/CLOVER/Clover+4.0+Release+Notes

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

https://stackoverflow.com/questions/27633694

复制
相关文章

相似问题

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