【发布时间】:2016-05-12 16:17:16
【问题描述】:
最近开始发生这种情况,但我不确定是什么变化导致了它。
- 当我从 IntelliJ 运行所有测试时,一切正常。 gradle构建也很好。
- 当我运行一个单元测试时,一切都很好。
- 当我运行单个 Web 集成测试时,它会失败,因为配置类具有所有空属性。
配置类看起来像(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())
}
我不确定我可以添加哪些信息。根据提供的有限信息:
- 这是已知解决方案的已知问题吗?
【问题讨论】:
-
请向我们展示单个 Web 集成测试。
-
你去@miensol,谢谢
-
谢天谢地,它似乎可以在 IntelliJ 16 (EAP) 上运行,这很好,在解决了这个问题之后:stackoverflow.com/q/35178407/404201
-
我怀疑您可能遇到的问题是由于gradle spring boot 插件和idea 对待资源的方式不同造成的。您可以通过检查单个现在失败的测试在 Idea 中调用重建项目后是否仍然失败来验证这一点。
-
@miensol 这听起来确实有道理。我不能绝对肯定地告诉你,因为我回到 IntelliJ 15(我一直在使用 16 EAP)来验证你的建议,它已经停止发生了。
标签: java spring intellij-idea spring-boot kotlin