Automatic DB Connection from Spring Boot Test [Ultimate]
已回答
HI,
we are using zonky embedded-database-spring-test to automatically start a database for our spring boot service tests:
<dependency>
<groupId>io.zonky.test</groupId>
<artifactId>embedded-database-spring-test</artifactId>
<version>2.1.1</version>
<scope>test</scope>
</dependency>
When running a test i can see the connection URL printed to the log and can manually change the connection setting to connect to this db.
i.z.t.d.l.EmbeddedDatabaseReporter: JDBC URL to connect to 'dataSource':
url='jdbc:sqlserver://localhost:49154;databaseName=cywlsplkqkij;user=sa;password=A_Str0ng_Required_Password', scope='ClientControllerTests#createClientsTest'
Is there a way that IntelliJ can automatically connect to this db (eg.: from running spring boot test conext)?
This would be quite useful for debugging to avoid searching the connection URL in the logs and updating the config for every test run.
We are using Postgres and MSSQL Server.
请先登录再写评论。
No such option. Data source configuration is in <project_folder>\.idea\dataSources.xml file, and passwords are stored in KeePass database (or native key chain, depending on OS), so you can try to create some script which will edit values...
I've prepared a Groovy script to LivePlugin that watches the log and updates the database settings in IntelliJ IDEA according to it.
Here are the instructions:
1. Install the LivePlugin plugin
2. In LivePlugin, create a new Groovy plugin and copy the snippet below into the newly created plugin.groovy file
3. In IntelliJ IDEA, create a new data source with the corresponding name and driver (embedded-postgres, embedded-sqlserver, ... - names and types are configurable at the beginning of the script)
4. Run the plugin and from that moment the database settings will be synchronized with the log
We've created a request for this feature to be implemented.