SpringBoot课程学习(一)
@SpringBootTest指定测试的启动类
声明@SpringBootTest
@Test注解
@Test 指定测试方法
@Order排序
一:先声明排序模式
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)//设置排序模式
二:使用Order()括号内放顺序先后
@Test
@Order(2)
public void testA(){
}
@Test
@Order(1)
public void testB(){
}
总体:
结果:
注解(@BeforeEach、@BeforeAll、@AfterEach、@AfterAll)
代码:
@BeforeAll
public static void beforeAll(){
System.out.println("beforeAll在所有单元测试方法执行前执行一遍");//只执行一次
}
@BeforeEach
public void beforeEach(){
System.out.println("beforeEach每个测试方法前,执行该方法");
}
@AfterEach
public void afterEach(){
System.out.println("afterEach在每个单元测试方法执行后都执行一遍");
}
@AfterAll
public static void afterAll(){
System.out.println("afterAll在测试方法执行后都执行一遍");//只执行一次
}
结果:
@DisplayName()用于指定单元测试的名称
@DisplayName("测试断言equals")
结果:
@Disabled 禁用测试
在方法头部添加@Disabled
@RepeatedTest重复测试
在方法头部添加@RepeatedTest
结果:
@ParameterizedTest、@ValueSource参数化参数
一:先声明该方法为参数化测试 @ParameterizedTest
二:在@ValueSource里添加参数源
结果: