使用JUnit 5的@ExtendWith注释来指定扩展,并在测试类级别上将其应用于所有测试方法。
示例代码:
@ExtendWith(MyExtension.class)
public class MyTest {
@Test
void testOne() {
// test one
}
@Test
void testTwo() {
// test two
}
//... additional test methods
}
在上面的示例中,我们使用@ExtendWith注释在测试类级别上应用MyExtension扩展,以便将其应用于所有测试方法。这样,我们就可以避免在每个测试方法上重复扩展的指定。