我有一个用Spring开发的Spring应用程序。顺便说一句,这只是为了学习的目的。
默认情况下,应用程序启动并使用MySQL数据库。对于单元测试和集成测试,我使用内存中的H2数据库,它工作得很好.
因此,我有两个application.properties。一个在/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/src/test/resources/application.properties下的另一个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现在,我必须使用Selenium进行自动网站测试,而且我不希望我的MySQL数据库中填充测试数据。
以前我还没有在Spring中这样做过,但是我希望我的应用程序能够这样工作:
如何在使用application.properties或其他配置的Spring应用程序中做到这一点?
发布于 2017-09-20 21:11:38
application-test.properties的单独属性文件,并将其放在/src/test/resources下。测试数据库属性(或任何其他特定于测试的属性)应该放在这里。@ActiveProfiles("test")。
@ActiveProfiles("test")公共类MyTest {.}发布于 2017-09-20 05:50:03
https://stackoverflow.com/questions/46313926
复制相似问题