Spring2.4.5.
正在尝试运行测试示例。
2022-06-30 21:58:39.897 INFO --- [ Test worker] .b.t.c.SpringBootTestContextBootstrapper : Neither @ContextConfiguration nor @ContextHierarchy found for test class [dataset.status.dashboard.api.repository.StatusRepositoryIntegrationTest], using SpringBootContextLoader
2022-06-30 21:58:39.901 INFO --- [ Test worker] o.s.t.c.support.AbstractContextLoader : Could not detect default resource locations for test class [dataset.status.dashboard.api.repository.StatusRepositoryIntegrationTest]: no resource found for suffixes {-context.xml, Context.groovy}.
2022-06-30 21:58:39.902 INFO --- [ Test worker] t.c.s.AnnotationConfigContextLoaderUtils : Could not detect default configuration classes for test class [dataset.status.dashboard.api.repository.StatusRepositoryIntegrationTest]: StatusRepositoryIntegrationTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
2022-06-30 21:58:39.961 INFO --- [ Test worker] .b.t.c.SpringBootTestContextBootstrapper : Found @SpringBootConfiguration company.status.dashboard.api.App for test class dataset.status.dashboard.api.repository.StatusRepositoryIntegrationTest
2022-06-30 21:58:40.013 INFO --- [ Test worker] .b.t.c.SpringBootTestContextBootstrapper : Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.event.ApplicationEventsTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener]
2022-06-30 21:58:40.022 INFO --- [ Test worker] .b.t.c.SpringBootTestContextBootstrapper : Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@5be3295e, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@48ec863b, org.springframework.test.context.event.ApplicationEventsTestExecutionListener@37762e2a, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@4db30010, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@f586921, org.springframework.test.context.support.DirtiesContextTestExecutionListener@23a9fbaf, org.springframework.test.context.transaction.TransactionalTestExecutionListener@2528968e, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@70cea1bb, org.springframework.test.context.event.EventPublishingTestExecutionListener@3c93dfe2, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@500b2f5c, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@31f64f35, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@3430e3c9, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@16fe5662, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener@1f06ea2e, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@1c8a911c]
2022-06-30 21:58:40.025 INFO --- [ Test worker] .b.t.c.SpringBootTestContextBootstrapper : Neither @ContextConfiguration nor @ContextHierarchy found for test class [dataset.status.dashboard.api.repository.StatusRepositoryIntegrationTest$FindFirstDailyDeliveryStatusesByDatasetUnitWithinTimeRange], using SpringBootContextLoader
2022-06-30 21:58:40.025 INFO --- [ Test worker] o.s.t.c.support.AbstractContextLoader : Could not detect default resource locations for test class [dataset.status.dashboard.api.repository.StatusRepositoryIntegrationTest$FindFirstDailyDeliveryStatusesByDatasetUnitWithinTimeRange]: no resource found for suffixes {-context.xml, Context.groovy}.
2022-06-30 21:58:40.026 INFO --- [ Test worker] t.c.s.AnnotationConfigContextLoaderUtils : Could not detect default configuration classes for test class [dataset.status.dashboard.api.repository.StatusRepositoryIntegrationTest$FindFirstDailyDeliveryStatusesByDatasetUnitWithinTimeRange]: FindFirstDailyDeliveryStatusesByDatasetUnitWithinTimeRange does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
2022-06-30 21:58:40.027 INFO --- [ Test worker] .b.t.c.SpringBootTestContextBootstrapper : Found @SpringBootConfiguration company.status.dashboard.api.App for test class dataset.status.dashboard.api.repository.StatusRepositoryIntegrationTest$FindFirstDailyDeliveryStatusesByDatasetUnitWithinTimeRange
2022-06-30 21:58:40.029 INFO --- [ Test worker] .b.t.c.SpringBootTestContextBootstrapper : Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.event.ApplicationEventsTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener]
2022-06-30 21:58:40.029 INFO --- [ Test worker] .b.t.c.SpringBootTestContextBootstrapper : Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@14f0dd2a, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@6c6b8304, org.springframework.test.context.event.ApplicationEventsTestExecutionListener@370431a5, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@491f8897, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@5b140513, org.springframework.test.context.support.DirtiesContextTestExecutionListener@6b57ced6, org.springframework.test.context.transaction.TransactionalTestExecutionListener@7dc84300, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@48a6371e, org.springframework.test.context.event.EventPublishingTestExecutionListener@33e18f84, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@6695c650, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@59fa49c1, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@201d9b27, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@1f3fbd0f, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener@57d05ffe, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@5cefa084]
2022-06-30 21:58:40.183 INFO 69695 --- [ Test worker] .StatusRepositoryIntegrationTest : Starting StatusRepositoryIntegrationTest using Java 11.0.15 on C12346 with PID 69695 (started by alex in /Users/alex/projects/status-dashboard-api)
2022-06-30 21:58:40.183 INFO 69695 --- [ Test worker] .StatusRepositoryIntegrationTest : The following profiles are active: local
正在从main.java.resources.application-local.properties
获取测试配置,而必须从test.java.resources
文件夹获取。
我在IntelliJ Idea的Run/Debug Configurations
窗口中尝试了不同的选项SPRING.PROFILES.ACTIVE
、spring.profiles.active
、SPRING_PROFILES_ACTIVE
,值为test
,但它确实有帮助。
我要运行的测试具有以下注解:
@ExtendWith(SpringExtension.class)
@SpringBootTest
@TestPropertySource(locations = {"classpath:application-integration.properties"})
class StatusRepositoryIntegrationTest {
1条答案
按热度按时间0ejtzxu11#
spring.profiles.active
是指如果您没有配置另一个配置文件,当前将处于活动状态的配置文件。如果您想使用另一个配置文件运行,请参阅this。当然,如果您配置另一个配置文件,则必须
application-<profile_name>.properties/yml
您不需要
@TestPropertySource
,因为Spring会在test和main文件夹中找到它。如果在main和test中有两个同名的文件,我注意到它们会相互覆盖。* 我没有测试配置是作为完整文件覆盖还是只通过test扩展。*如果您只想运行测试或将设置应用于特定的配置文件,则需要@ActiveProfile(“配置文件”)。
要了解有关配置文件的更多信息,请阅读this。
如果我们看一下上面提到的例子。
mvn/gradle测试命令
-Dspring.profiles.active=integration
或--spring.profiles.active=integration