我在测试期间没有阅读application.properties
和application-test.properties
的Spring启动存在问题。
这是我的测试类:
public class SignupRestControllerTest extends AbstractEnd2EndIntegrationTest {
...
这是AbstractEnd2EndIntegrationTest
类:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = { TestEnd2EndIntegrationConfiguration.class })
@WebAppConfiguration
@ActiveProfiles(Profiles.TEST)// "test"
@Transactional
public abstract class AbstractEnd2EndIntegrationTest {
}
我可以看到我使用@SpringApplicationConfiguration
所以我的测试应该使用Spring启动......
我使用gradle来运行测试:
sourceSets {
main {
output.resourcesDir = output.classesDir
}
integrationTest {
java.srcDirs = ['src/it/java']
resources.srcDirs = ['src/it/resources', 'src/main/resources']
compileClasspath = sourceSets.main.output + configurations.testRuntime
runtimeClasspath = output + compileClasspath
}
}
task integrationTest(type: Test) {
description "Run the integration tests."
testClassesDir = sourceSets.integrationTest.output.classesDir
classpath = sourceSets.integrationTest.runtimeClasspath
reports.html.destination = file("$reports.html.destination/integration")
reports.junitXml.destination = file("$reports.junitXml.destination/integration")
}
来自application.properties
(src/main/resources
):
database.hibernate.ejb.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy
我得到例外:
Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException
有人可以帮忙吗?
答案 0 :(得分:1)
我刚刚遇到此问题,并通过将ConfigFileApplicationContextInitializer
添加到@ContextConfiguration
来解决此问题。在这种情况下得到的注释将是:
@SpringApplicationConfiguration(
classes = TestEnd2EndIntegrationConfiguration.class,
initializers = ConfigFileApplicationContextInitializer.class)