JUNIT测试通过,但是hansel测试覆盖率的时候报错了,报错信息如下 求支援

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JUNIT测试通过,但是hansel测试覆盖率的时候报错了,报错信息如下 求支援相关的知识,希望对你有一定的参考价值。

junit.framework.AssertionFailedError: No tests found in tteesstt.MyAHansel
at junit.framework.Assert.fail(Assert.java:47)
at junit.framework.TestSuite$1.runTest(TestSuite.java:263)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

参考技术A code 贴code 出来看

spring && Cobertura && maven &&junit 单元测试以及测试覆盖率

 1. 目的:

 
      junit 单元测试,Cobertura   测试覆盖率报告
      项目目录结构
      
 
2. maven 配置
   
  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  3. <modelVersion>4.0.0</modelVersion>
  4. <groupId>com.dalong.demoapp</groupId>
  5. <artifactId>junitdemo</artifactId>
  6. <version>0.0.1-SNAPSHOT</version>
  7. <dependencies>
  8. <dependency>
  9. <groupId>org.springframework</groupId>
  10. <artifactId>spring-test</artifactId>
  11. <version>4.3.5.release</version>
  12. </dependency>
  13. <dependency>
  14. <groupId>junit</groupId>
  15. <artifactId>junit</artifactId>
  16. <version>4.12</version>
  17. </dependency>
  18. <dependency>
  19. <groupId>org.springframework</groupId>
  20. <artifactId>spring-web</artifactId>
  21. <version>4.3.5.release</version>
  22. </dependency>
  23. </dependencies>
  24. <build>
  25. <plugins>
  26. <plugin>
  27. <groupId>org.codehaus.mojo</groupId>
  28. <artifactId>cobertura-maven-plugin</artifactId>
  29. <version>2.7</version>
  30. <configuration>
  31. <formats>
  32. <format>xml</format>
  33. </formats>
  34. </configuration>
  35. <executions>
  36. <execution>
  37. <phase>package</phase>
  38. <goals>
  39. <goal>cobertura</goal>
  40. </goals>
  41. </execution>
  42. </executions>
  43. </plugin>
  44. </plugins>
  45. </build>
  46. </project>
 
3. spring 代码
 
   
  1. package junitdemo;
  2. import org.springframework.context.annotation.Bean;
  3. import org.springframework.context.annotation.Configuration;
  4. @Configuration
  5. publicclassUserOperator{
  6. @Bean
  7. publicUserService userService(){
  8. UserService info =newUserService();
  9. return info;
  10. }
  11. }
  1. package junitdemo;
  2. import java.util.Date;
  3. publicclassUserService{
  4. publicUserInfo userInfo(){
  5. UserInfo info =newUserInfo();
  6. info.setDate(newDate());
  7. info.setAge(333);
  8. info.setInfo("dddddd");
  9. return info;
  10. }
  11. }
  1. package junitdemo;
  2. import java.util.Date;
  3. publicclassUserInfo{
  4. privateDate date;
  5. publicDate getDate(){
  6. return date;
  7. }
  8. publicvoid setDate(Date date){
  9. this.date = date;
  10. }
  11. publicString getInfo(){
  12. return info;
  13. }
  14. publicvoid setInfo(String info){
  15. this.info = info;
  16. }
  17. publicint getAge(){
  18. return age;
  19. }
  20. publicvoid setAge(int age){
  21. this.age = age;
  22. }
  23. privateString info;
  24. privateint age;
  25. }
4. junit 测试代码
   
  1. package junitdemo;
  2. import org.junit.Test;
  3. import org.junit.runner.RunWith;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.test.context.ContextConfiguration;
  6. import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  7. @RunWith(SpringJUnit4ClassRunner.class)
  8. @ContextConfiguration(classes =UserOperator.class)
  9. publicclassUserOperatorTest{
  10. @Autowired
  11. publicUserService userService;
  12. @Test()
  13. publicvoid testUserOperator(){
  14. for(int i =0; i <100; i++){
  15. UserInfo info = userService.userInfo();
  16. System.out.println(info.toString());
  17. }
  18. }
  19. }
5. 生成测试报告
 
  1. mvn cobertura:cobertura
6. 生成的报告
 
   
 
7. 扩展
 
     集成jenkins 进行后期的统计,以及及时查看信息
 
  
 

以上是关于JUNIT测试通过,但是hansel测试覆盖率的时候报错了,报错信息如下 求支援的主要内容,如果未能解决你的问题,请参考以下文章

如何通过非 maven 项目的声纳的 junit 测试来测量代码覆盖率

JUnit 测试通过但 PIT 说套件不是绿色的

通过Maven一起运行jUnit和spock测试

JUnit 单元测试

Intellij idea Junit单元测试不显示代码覆盖率

AVLTree JUnit测试用例