Spring-boot使用Spring配置文件(http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-profiles.html),它允许例如为不同的环境分别配置.我使用此功能的一种方法是配置测试数据库以供集成测试使用.我想知道是否有必要创建我自己的配置文件'test'并在每个测试文件中明确激活此配置文件?现在我用以下方式做到:
在每个测试文件中包括:
@ActiveProfiles("test")
Run Code Online (Sandbox Code Playgroud)有更聪明/更简洁的方式吗?例如,默认测试配置文件?
编辑1:这个问题与Spring-Boot 1.4.1有关
我有一个使用 Spring Boot 和 Junit 5 的简单应用程序:
使用 Spring Boot 2.1(例如 2.1.8 或 2.1.12)时,我的单元测试运行顺利
使用 Spring Boot 2.2(例如 2.2.2.RELEASE 或 2.3.2.RELEASE)时,我的单元测试失败并显示错误消息
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project XXX: There are test failures.
[ERROR]
[ERROR] Please refer to D:\Projets\workspace\XXX\target\surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] There was an error in the forked process
[ERROR] TestEngine with ID 'junit-vintage' failed to discover tests
[ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: There …Run Code Online (Sandbox Code Playgroud)