jck28-lucio-junit5测试框架结构

01-JUnit5 多个类之间的继承关系

问题

如果是两个 Test 类,A类和B类,其中B类继承A类。两个类都有 beforeall,beforeEach,afterAll,afterEach,那么执行顺序???

![|438x336](file:///C:\Users\86159\AppData\Local\Temp\ksohtml15304\wps1.jpg)

02-JUnit5 多继承示例代码

package com.junit5.extendstest;

import org.junit.jupiter.api.*;

public class BaseATest {

@BeforeAll

static void testBeforeAllA(){

System.out.println(“BaseATest—BeforeAll”);

}

@AfterAll

static void testAfterAllA(){

System.out.println(“BaseATest—AfterAll”);

}

@BeforeEach

void testBeforeEachA(){

System.out.println(“BaseATest—BeforeEach”);

}

@AfterEach

void testAfterEachA(){

System.out.println(“BaseATest—AfterEach”);

}

@Test

public void hogwartsATest01(){

System.out.println(“BaseATest—hogwartsATest01”);

}

@Test

public void hogwartsATest02(){

System.out.println(“BaseATest—hogwartsATest02”);

}

}

package com.junit5.extendstest;

import org.junit.jupiter.api.*;

public class BaseBTest extends BaseATest{

@BeforeAll

static void testBeforeAllB(){

System.out.println(“BaseBTest—BeforeAll”);

}

@AfterAll

static void testAfterAllB(){

System.out.println(“BaseBTest—AfterAll”);

}

@BeforeEach

void testBeforeEachB(){

System.out.println(“BaseBTest—BeforeEach”);

}

@AfterEach

void testAfterEachB(){

System.out.println(“BaseBTest—AfterEach”);

}

@Test

public void hogwartsBTest01(){

System.out.println(“BaseBTest—hogwartsBTest01”);

}

@Test

public void hogwartsBTest02(){

System.out.println(“BaseBTest—hogwartsBTest02”);

}

}

![|305x484](file:///C:\Users\86159\AppData\Local\Temp\ksohtml15304\wps2.jpg)

![|330x101](file:///C:\Users\86159\AppData\Local\Temp\ksohtml15304\wps3.jpg)

03-Junit5 注解的继承关系

官方网站对于继承关系的总结

https://junit.org/junit5/docs/current/user-guide/