1

我有一个简单的autowired控制器和测试。当项目使用mvn和代码覆盖目标emma:emma和emma进行构建时:check,测试用例会失败,并显示以下错误。NoClassDefFoundError与弹簧3.1控制器单元测试

简单的“mvn test”命令成功。 “mvn test emma:emma emma:check”失败。

java.lang.NoClassDefFoundError: org/springframework/web/bind/support/WebDataBinderFactory 

回答

0

使用的Cobertura尝试,将它添加到您的报告部分:

<reporting> 
    <plugins> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>cobertura-maven-plugin</artifactId> 
      <version>2.5.1</version> 
      <configuration> 
       <check> 
       <lineRate>120</lineRate> 
       </check> 
      </configuration> 
     </plugin> 
    </plugins> 
</reporting> 

然后执行:

mvn site 

然后在浏览器中打开:

target/site/index.html 

你会看到cobertura报告在那里。 最好将这些类型的插件添加到您的父pom中。

0

你在测试中是否具有spring-web的依赖性。如果不是,则尝试添加依赖关系org.springframework:spring-web