简体   繁体   English

Spring Boot配置测试数据库

[英]Spring boot configure test database

I need to add tests to my Spring Boot project. 我需要将测试添加到我的Spring Boot项目中。 With rails framework there is dev and test databases which are created when new project is started. 使用Rails框架,可以在启动新项目时创建开发和测试数据库。 Migrations are applied to both databases to keep the database schemas equal. 迁移将应用于两个数据库,以保持数据库架构相等。 Unfortunately I didn't find the documentation on how to configure test environment database in Spring boot and how to get the database structure equal to dev. 不幸的是,我找不到关于如何在Spring Boot中配置测试环境数据库以及如何获得与dev相等的数据库结构的文档。

What is the best practice for testing in Spring Boot? 在Spring Boot中进行测试的最佳实践是什么? How to setup and add test-data for the test environment? 如何为测试环境设置和添加测试数据? Is there any examples? 有没有例子?

You can use profiles in spring which allow to use different configuration. 您可以在spring中使用配置文件,以允许使用其他配置。 So in DEV Profile you tell spring you want to point to dev database but in TEST Profile run in another database. 因此,在DEV Profile中,您告诉spring您想指向dev数据库,但在TEST Profile中 ,它在另一个数据库中运行。

Check this link: http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-profiles.html 检查此链接: http : //docs.spring.io/spring-boot/docs/current/reference/html/boot-features-profiles.html

If you want to manage delta scripts you can use flyway or liquibase. 如果要管理增量脚本,则可以使用flyway或liquibase。 Both are supported by spring-boot. 两者都受spring-boot支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM