Junit六大注解使用

参考博客:https://blog.csdn.net/weixin_39651356/article/details/103585674 JUnit单元测试六大常用 - @Test、@Before、@After、@BeforeClass、@AfterClass、@Ignore
Junit6大注解
@Test:表示当前方法是一个测试方法,- 修饰非静态方法
@BeforeClass
@AfterClass
@Before
@After
@Ignore:用在类上,所有测试注解修饰的方法都不会执行;用在方法上,用在@Test测试方法上才有效,表示该测试方法将被忽略(执行测试类,测试类可能有多个@Test方法)

junit4 junit5 特点
@BeforeClass @BeforeAll 最先运行,且只运行一遍 - 修饰静态方法
@AfterClass @AfterAll 所有注解运行完毕,才最后运行,只运行一遍 - 修饰静态方法
@Before @BeforeEach 紧随在@Test运行之前,有多少个@Test就运行多少遍 - 同@Test共存亡 - 修饰非静态方法
@After @AfterEach 紧随在@Test运行之后,有多少个@Test就运行多少遍 - 同@Test共存亡 - 修饰非静态方法

posted @ 2022-07-12 01:41  让时间变成力量  阅读(139)  评论(0)    收藏  举报