记住:Junit5 依赖的是java8,java7以下的版本测试会报错!
Annotation | Description |
---|---|
@Test | 表示一种方法是一种测试方法,这个注解没有声明任何属性. |
@ParameterizedTest | 表示方法是参数化测试。 |
@RepeatedTest | 表示方法是重复测试的测试模板。 |
@TestFactory | 表示方法是动态测试的测试工厂。 |
@TestInstance | 用于配置注释测试类的测试实例生命周期。 |
@TestTemplate | 表示一个方法是测试用例的模板。 |
@DisplayName | 声明测试类或测试方法的自定义显示名称。此方法不能被继承 |
@BeforeEach | 表示注释的方法应在当前类的每个 @Test,@RepeatedTest,@ParameterizedTest或@TestFactory方法之前执行; 类似于JUnit 4的@Before |
@AfterEach | 表示应该在当前类中的每个@Test,@RepeatedTest,@ParameterizedTest或@TestFactory方法之后执行带注释的方法; 类似于JUnit 4的@After。 |
@BeforeAll | 表示注释的方法应该在当前类的所有@Test,@RepeatedTest,@ParameterizedTest和@TestFactory方法之前执行; 类似于JUnit 4的@BeforeClass。 |
@AfterAll | 表示注释的方法应该在当前类的所有@Test,@RepeatedTest,@ParameterizedTest和@TestFactory方法之后执行; 类似于JUnit 4的@AfterClass |
@Nested | 表示注释的类是一个嵌套的非静态测试类。 除非使用“per-class”测试实例生命周期,否则@BeforeAll和@AfterAll方法不能直接在@Nested测试类中使用 |
@Tag | 用于在类或方法级别声明过滤测试的标签; 类似于TestNG中的测试组或JUnit 4中的类别 |
@Disabled | 用于禁用测试类或测试方法; 类似于JUnit 4的@Ignore。 |
@ExtendWith | 用于注册自定义扩展。 |
上面都是Junit 5 锁涉及到的注解。
网友评论