Reputation: 725
I have been struggling with the issue of starting the H2 db in my tests. This is how the tests are annotated -
@SpringApplicationConfiguration(classes = ServiceApplication.class)
@WebAppConfiguration
@IntegrationTest("server.port:8084")
@PropertySource("test:application.properties")
public class testSerivce{
//test scenario
}
The in memory db H2 is used and this is how its setup in application property file -
dataSource.driverClassName=org.h2.Driver
dataSource.url=jdbc:h2:tcp://localhost:59000/./target/service-db;MODE=Oracle;IGNORECASE=TRUE;IFEXISTS=TRUE
dataSource.username=sa
dataSource.password=sa
dataSource.maxActive=2
dataSource.initialSize=1
dataSource.maxIdle=1
When I right click and run the tests the H2 db is not getting setup with the service and the tests are not able to connect with database and failing.
Whereas when I run the tests using the maven profile,as thy are running in teamcity everything works and the tests work but it runs all the 10tests .
What should I do? I am stuck at this issue for many days. Which annotation should I use or how to setup the H2 setup so that they also run with the service.
Upvotes: 1
Views: 1360
Reputation: 101
Are you using Eclipse? I somehow noticed that src/main/resources/application.properties gets excluded from the Java Build Path, if you generate the project with the "eclipse:eclipse" maven goal.
To workaround this you can either add a src/test/resources/application.properties or correct the Java Build Path.
I don't know if this behavior is intended. I guess it is because of the resource exclusions/inclusions in spring-boot-starter-parent
Upvotes: 1