gpt4 book ai didi

spring-boot - 在junit5中使用SpringRunner有什么特别的配置吗?

转载 作者:行者123 更新时间:2023-12-03 15:42:39 25 4
gpt4 key购买 nike

我的微服务项目基于 spring-boot 框架,我所有的单元测试都在 spring runner 上运行。

@RunWith(SpringRunner.class)

添加此注释,导入以下库:
import org.springframework.test.context.junit4.SpringRunner;

如何将我的测试类设置为与 junit5 一起运行?

最佳答案

从构建路径中删除 JUnit4。
例如 :

@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
@TestPropertySource(locations = "classpath:application-local.properties")
public class MyTest {
@Before
public void setUp() {
...
}

@Test
public void testMethod() {
Assert.assertTrue(...);
}
}
会变成
@SpringBootTest(classes = Application.class)
@TestPropertySource(locations = "classpath:application-local.properties")
public class MyTest {
@BeforeEach
public void setUp() {
...
}
@Test
public void testMethod() {
Assertions.assertTrue(...);
}
}

关于spring-boot - 在junit5中使用SpringRunner有什么特别的配置吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61088682/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com