跳过测试方法(测试类)(@Ignore)

1.什么情况下要使用跳过测试(测试类)方法?

  • 写了一个测试方法但是不想执行
    1. 删掉该测试方法(测试类)
    2. 注释该测试方法(测试类)
    3. 使用@Ignore注解

2.示例

2.1 必要工作

  • 导入类库

import org.junit.Ignore;

2.2 使用@Ignore注解跳过测试方法

@Ignore方法写测试类上 代表该方法在执行时要跳过

  • 代码
javascript 复制代码
package com.jaylan.example;
import  org.junit.Test;
import  org.junit.Ignore;
//使用@Ignore跳过测试方法
public class ExampleTest_4_Ingore {

    @Test
    public void testMethod_1() {
	System.out.println("这里是testMethod_1");
    }
    
    @Test
    @Ignore//跳过该方法
    public void testMethod_2() {
 	System.out.println("这里是testMethod_2");
     }
    
    @Test
    public void testMethod_3() {
 	System.out.println("这里是testMethod_3");
     }
   
    
}

2.3 使用@Ignore注解跳过测试类

  • 使用@Ignore跳过测试类

整个测试类被跳过 其中的一个测试方法都不执行

@Ignore写在类上

  • 代码
javascript 复制代码
package com.jaylan.example;
import  org.junit.Test;
import  org.junit.Ignore;
//使用@Ignore跳过测试类
@Ignore //跳过整个测试类(该类下包含的所有方法都不执行)
public class ExampleTest_4_Ingore2 {

    @Test
    public void testMethod_1() {
	System.out.println("这里是testMethod_1");
    }
    
    @Test
    public void testMethod_2() {
 	System.out.println("这里是testMethod_2");
     }
    
    @Test
    public void testMethod_3() {
 	System.out.println("这里是testMethod_3");
     } 
}

3.总结

  • @Ignore用来跳过测试类或者测试方法
  • @Ignore的位置不同 其作用不同
    • 写在类上→跳过整个测试类
    • 写在方法上跳过该测试方法
  • 使用@Ignore之前要导入 import org.junit.Ignore;
相关推荐
Zero_pl9 小时前
黑盒测试、白盒测试、单元测试、集成测试、系统测试、验收测试的区别与联系
单元测试·集成测试
风与沙的较量丶9 小时前
单元测试方法的使用
单元测试·log4j
2501_9032386513 小时前
深入理解 JUnit 的 @RunWith 注解与自定义 Runner
数据库·junit·sqlserver·个人开发
odoo中国15 小时前
Part 3 第十二章 单元测试 Unit Testing
单元测试·软件工程
Zero_pl15 小时前
单元测试的策略有哪些,主要包括什么?
单元测试
陈小咩咩17 小时前
IDEA单元测试插件 SquareTest 延长试用期权限
java·单元测试·intellij-idea
Rhys..2 天前
Jenkins上无法查看已成功生成的Junit报告
junit·sqlserver·jenkins
Rhys..2 天前
如何生成Junit报告
python·junit·jenkins
ihengshuai2 天前
Jest单元测试
单元测试·jest·前端自动化测试
阿湯哥2 天前
Lua脚本核心语法介绍
开发语言·junit·lua