【发布时间】:2020-06-22 23:37:54
【问题描述】:
我使用的是springboot 2.2.2.RELEASE版本。
我正在尝试使用 junit5 添加测试,这是我在 build.gradle 中的设置方式:
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'junit', module: 'junit'
}
testImplementation "org.junit.jupiter:junit-jupiter-api:5.5.2"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.5.2"
这是我的测试课:
//@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT, classes = UserServiceApplication.class)
@ActiveProfiles("it")
public class UserControllerIntegrationTest {
@Autowired
private TestRestTemplate testRestTemplate;
}
问题是restRestTemplate 为空。它起作用的唯一方法是当我使用时:
@RunWith(SpringRunner.class)
不过,据我了解,这是为了支持junit4,对吧?
我正在使用未弃用的 TestRestTemplate (org.springframework.boot.test.web.client.TestRestTemplate)。
我也尝试添加以下内容,但也没有用:
@ExtendWith(SpringExtension.class)
我错过了什么?
谢谢。
【问题讨论】:
标签: spring-boot spring-boot-test