I have some unit test classes in my project that I want to test with mvn test
. But whenever I run the command an instance of spring boot starts and opens database connections.
I´m running these tests in a server that doesn´t have access to a database, and none of my tests uses one. I just one to execute the tests as the IDE does.
CodePudding user response:
I think one of them could help you
1 - Disable all tests
mvn clean install -DskipTests
2 - Prepare your test for switching
@ExtendWith(SpringExtension.class)
@EnabledIf(expression = "${tests.spring.enabled:true}")
if you pass -Dtests.spring.enabled=
false or true will disable test
3 - Point your test to other configuration
@ExtendWith(SpringExtension.class)
@TestPropertySource(locations = "classpath:application-${spring.profiles.active:test}.properties")
this way you could connect your application into a local database
4 - Change your tests
Use mocks to turn your integration tests into a unit tests or component tests with no connections
CodePudding user response:
The problem I had was an empty class with @SpringBootTest
annotation. After deleting it the tests works without spring interfering.