Spring 开机无法运行 IntelliJ 单机测试
Spring Boot can't run single test in IntelliJ
最近开始出现这种情况,但我不确定是什么原因导致的。
- 当我 运行 从 IntelliJ 进行所有测试时,一切都很好。 gradle 构建也很好。
- 当我运行单个单元测试时,一切都很好。
- 当我 运行 单个 Web 集成测试时,它失败了,因为配置 class 具有所有空属性。
配置 class 看起来像 (Kotlin):
@Component
@ConfigurationProperties(prefix = "api")
public open class ApiConfigImpl : ApiConfig
{
测试如下:
@RunWith(SpringJUnit4ClassRunner::class)
@ContextConfiguration(classes = arrayOf(ApplicationAssembly::class), loader = SpringApplicationContextLoader::class)
@WebIntegrationTest
open class CandidateProfileControllerTest
{
@Inject lateinit var profileRepo: CandidateProfileRepository
//etc a few more deps used to setup test data
@Test
open fun getById()
{
val greg = CandidateProfile("123", "12312", "Greg", "Jones", dateOfBirth = Date(), gender = Gender.MALE,
biography = "ABC", maxMatchableAge = null, maxMatchableDistance = null)
profileRepo.save(greg)
val auth = given().header("content-type", "application/json")
.body(testCredentials)
.post("/authorization/social").peek().asString()
val accessToken: String = from(auth).get("accessToken")
given().header("Access-Token", accessToken).
header("API-Key", testAPIKey()).
get("/profile/${greg.id}").
peek().then().
body("stageName", notNullValue())
}
我不确定我可以添加哪些信息。根据提供的有限信息:
- 这是已知解决方案的已知问题吗?
这是一个错误,已记录在 IntelliJ/Kotlin tracker 中,有待修复。
最近开始出现这种情况,但我不确定是什么原因导致的。
- 当我 运行 从 IntelliJ 进行所有测试时,一切都很好。 gradle 构建也很好。
- 当我运行单个单元测试时,一切都很好。
- 当我 运行 单个 Web 集成测试时,它失败了,因为配置 class 具有所有空属性。
配置 class 看起来像 (Kotlin):
@Component
@ConfigurationProperties(prefix = "api")
public open class ApiConfigImpl : ApiConfig
{
测试如下:
@RunWith(SpringJUnit4ClassRunner::class)
@ContextConfiguration(classes = arrayOf(ApplicationAssembly::class), loader = SpringApplicationContextLoader::class)
@WebIntegrationTest
open class CandidateProfileControllerTest
{
@Inject lateinit var profileRepo: CandidateProfileRepository
//etc a few more deps used to setup test data
@Test
open fun getById()
{
val greg = CandidateProfile("123", "12312", "Greg", "Jones", dateOfBirth = Date(), gender = Gender.MALE,
biography = "ABC", maxMatchableAge = null, maxMatchableDistance = null)
profileRepo.save(greg)
val auth = given().header("content-type", "application/json")
.body(testCredentials)
.post("/authorization/social").peek().asString()
val accessToken: String = from(auth).get("accessToken")
given().header("Access-Token", accessToken).
header("API-Key", testAPIKey()).
get("/profile/${greg.id}").
peek().then().
body("stageName", notNullValue())
}
我不确定我可以添加哪些信息。根据提供的有限信息:
- 这是已知解决方案的已知问题吗?
这是一个错误,已记录在 IntelliJ/Kotlin tracker 中,有待修复。