跳过测试方法(测试类)(@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;
相关推荐
2302_805771071 天前
Day13Jmeter数据驱动
功能测试·单元测试·测试用例·需求分析·测试
2302_805771071 天前
Day14Jmeter+数据库的操作
功能测试·单元测试·测试用例·需求分析
清风~徐~来1 天前
【软件测试】allure 测试报告模块
单元测试
2302_805771071 天前
Day18在接口自动化测试中引入pytest用例管理框架
功能测试·单元测试·测试用例·需求分析·测试
CAE虚拟与现实3 天前
什么是浏览器冒烟测试
单元测试·测试·冒烟测试·回归测试
写后端的胖头鱼4 天前
一文学会单元测试之----Junit
junit·单元测试
FungLeo6 天前
成为全栈·Node 后端篇·后端测试策略:单元、集成与测试数据库
单元测试·node.js·集成测试·测试策略·成为全栈·测试数据库
yume_sibai6 天前
09-Rust 测试与质量保证(单元测试 + 集成测试 + Mock + Benchmark + Fuzzing + CI/CD)
rust·单元测试·集成测试
ChampaignWolf7 天前
Joule Unit Test 深度集成:ABAP 单元测试的 AI 六件套全解析
人工智能·单元测试·sap·abap·joule·单元测试ai
川石课堂软件测试7 天前
涨薪技术|Prometheus之HTTP API中使用PromQL
网络协议·测试工具·jmeter·http·单元测试·postman·prometheus