1

I have an issue with Spring boot not reading application.properties and application-test.properties during tests.

Here is my test class:

public class SignupRestControllerTest extends AbstractEnd2EndIntegrationTest {
 ...

and here is the AbstractEnd2EndIntegrationTest class:

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = { TestEnd2EndIntegrationConfiguration.class })
@WebAppConfiguration
@ActiveProfiles(Profiles.TEST)// "test"
@Transactional
public abstract class AbstractEnd2EndIntegrationTest {

}

One can see that I do use @SpringApplicationConfiguration so my test should be using Spring boot...

I use gradle to run the tests:

  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")
    }

from application.properties (in src/main/resources):

database.hibernate.ejb.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy

Exception I get:

 Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException

Can anyone please help?

3
  • shouldn't it just be hibernate.ejb.naming_strategy? Commented Sep 16, 2015 at 16:32
  • Thanks. It is actually a custom property that I retrieve with a @Value. Commented Sep 16, 2015 at 16:36
  • By the way are arbitrary/custom properties resolved the same way by spring boot during tests? Commented Sep 17, 2015 at 7:37

1 Answer 1

1

I just came across this and resolved it by adding ConfigFileApplicationContextInitializer to @ContextConfiguration. The resulting annotation in this case would be:

@SpringApplicationConfiguration(
classes = TestEnd2EndIntegrationConfiguration.class,
initializers = ConfigFileApplicationContextInitializer.class)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.