Allure2 添加用例标签简介
应用场景:提高测试用例的管理效率和测试过程的可视化程度。
用例标签的使用
- 正常测试用例添加标签。
- 用例跳过添加标签:
@DisabledIf
。 - 用例预期失败添加标签:
assumeFalse()
。
正常测试用例添加标签
- 测试用例正常运行场景。
@Tag("1")
@Tag("2")
public class TagTest {
@Test
@Tag("你好")
@Tag("世界")
void reTest() {
System.out.println("reTest");
}
}
用例跳过添加标签
通过@DisabledIf实现跳过用例。
@Test
@DisabledIf("good")
void test() {
System.out.println("执行te");
//Assumptions.assumeFalse(true, "This test is expected to fail");
// some test code that should fail
}
boolean good(){
//当前条件触发 如果是true 则测试方法test跳过不执行,并且结果默认为通过
return 2 + 2 != 5;
}
预期失败用例添加标签
通过assumeFalse()实现预期失败用例。
@Test
void test1() {
System.out.println("执行good1");
Assumptions.assumeFalse(this::good1, "这是一个预期失败的用例");
}
boolean good1(){
return 2 + 2 != 5;
}
用例跳过添加标签
- 通过@DisabledIf实现跳过用例。
@Test
@DisabledIf("good")
void test() {
System.out.println("执行te");
//Assumptions.assumeFalse(true, "This test is expected to fail");
// some test code that should fail
}
boolean good(){
//当前条件触发 如果是true 则测试方法test跳过不执行,并且结果默认为通过
return 2 + 2 != 5;
}
预期失败用例添加标签
- 通过assumeFalse()实现预期失败用例。
@Test
void test1() {
System.out.println("执行good1");
Assumptions.assumeFalse(this::good1, "这是一个预期失败的用例");
}
boolean good1(){
return 2 + 2 != 5;
}
package com.junit5.allure2casedesciption_l2.allurereport_addtag;
import io.qameta.allure.Allure;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.condition.DisabledIf;
import static org.junit.jupiter.api.Assertions.assertEquals;
@DisplayName("标签测试用例")
@Tag("1")
//@Tag("2")
@Tags({
@Tag("a"),
@Tag("b")
})
//@Tag与@Tags共存时,只能各一个,否则会报错
public class Allure2TagTest {
@Test
@Tag("你好")
@Tag("世界")
public void test1(){
System.out.println("这是一个标签测试用例");
}
@Test
@DisabledIf("good")
void test2() {
System.out.println("执行good");
assertEquals(23,4);
//Assumptions.assumeFalse(true, "This test is expected to fail");
// some test code that should fail
}
boolean good(){
//当前条件触发 如果是true 则测试方法test跳过不执行,并且结果默认为通过
return 2 + 2 != 5;
}
@Test
void test3() {
System.out.println("执行good1");
Assumptions.assumeFalse(this::good1, "This test is expected to fail");
// some test code that should fail
}
boolean good1(){
//当前条件触发 如果是true 则测试方法test跳过不执行,并且结果默认为通过
return 2 + 2 != 5;
}
}