I have a Spring MVC Application developed with Spring Boot. This is application is just for learning purposes, by the way.
By default, the app launches and uses a MySQL database. For unit and integration testing, I use an in-memory H2 database and it works perfectly.
So for that, I have two application.properties. One is under /src/main/resources/application.properties.
spring.datasource.driver-class-name = com.mysql.jdbc.Driver
spring.datasource.url = jdbc:mysql://localhost/myDatabase
spring.datasource.username = root
spring.datasource.password = mysql
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.cache=false
The other application.properties in under /src/test/resources/application.properties
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
spring.datasource.username=sa
spring.datasource.password=sa
Now, I have to use Selenium for automated website testing and I don't want my MySQL database to be populated with test data.
I haven't done this previously in Spring, but I would like my application to work like this:
- Launch from terminal my application with certain commands specifying what database it should use. It should launch on localhost:8080
- And then, run all Selenium test in localhost:8080. All the data generated with Selenium tests is only kept in memory as long as the application is running
How to do this in a Spring Boot Application using an application.properties or other configuration?