junit5 入门系列教程-03-junit5 测试类和方法

时间:2025-03-27 09:24:50

目录

  • 目录
  • 测试类和方法
    • 标准案例
  • 系列导航

测试类和方法

测试方法是使用@Test、@RepeatedTest、@ParameterizedTest、@TestFactory或@TestTemplate直接或元注释的任何实例方法。

测试类是包含至少一个测试方法的任何顶层或静态成员类。

标准案例

注意

测试类和测试方法都可以不设置为 public

import static ;

import ;
import ;
import ;
import ;
import ;
import ;

class StandardTests {

    @BeforeAll
    static void initAll() {
    }

    @BeforeEach
    void init() {
    }

    @Test
    void succeedingTest() {
    }

    @Test
    void failingTest() {
        fail("a failing test");
    }

    @Test
    @Disabled("for demonstration purposes")
    void skippedTest() {
        // not executed
    }

    @AfterEach
    void tearDown() {
    }

    @AfterAll
    static void tearDownAll() {
    }

}

系列导航

系列导航