跳过测试方法(测试类)(@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;
相关推荐
Sandy_Star1 天前
1.9 民法典及社会保险法制度规定
单元测试
xiufeia1 天前
后端项目初始化的一些小坑点
java·junit·maven·idea
Sandy_Star1 天前
1.7 税务行政法律救济
大数据·单元测试
Kiyra2 天前
Query Rewrite 不是越智能越好:RAG 检索的精确词保护与动态召回
redis·websocket·junit·单元测试·json
华万通信king2 天前
腾讯会议API集成测试实战:从单元测试到端到端自动化
单元测试·自动化·腾讯会议
姚青&3 天前
常用的测试平台
单元测试
kyriewen4 天前
你写的代码没有测试,就像出门不锁门——Jest + Testing Library 从入门到不慌
前端·单元测试·jest
qq_435287924 天前
第19章 十绝阵:十个独立沙箱环境?阐教逐个击破的渗透测试
渗透测试·单元测试·灰度发布·防御性编程·洪荒神话·十绝阵·沙箱环境
测试员周周4 天前
【AI测试功能6】功能测试的自动化率:哪些该自动、哪些必须人工——AI测试人机协作决策指南
开发语言·人工智能·python·功能测试·单元测试·自动化·测试用例
weixin_408099675 天前
触动精灵调用身份证OCR识别API实现智能信息录入(Lua脚本实战)
junit·ocr·lua·自动化脚本·石榴智能·身份证ocr识别·触动精灵