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