0

Id like to ask whether spring boot jpa test still needs to connect first to database before starting the test or not?

if not so it just uses the in-memory embedded database?

I am migrating a legacy app and its part of the test requirement (unit test) not to connect to database it self or any other services.

Update: so i just tried turning off mysql service and its failing. so it really is connecting still to database even if you have JpaTest annotation. how can we avoid this?

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Update:
I just use spring autoconfigure to make connection to my repository beans.

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
mark ortiz
  • 659
  • 1
  • 6
  • 13

1 Answers1

0

Spring Boot will try to connect as long as MySQL is configured either in Java Config or by means of application.properties. Can you provide additional information about how MySQL is configured in your context? Normally I introduce a specific Test Profile in my Spring Boot Application. See also: Profiles

claboran
  • 116
  • 2
  • 3
  • when you say profile - it is where you mock the datasource or jdbctemplate? so spring autoconfigure can backout? – mark ortiz Mar 04 '18 at 23:24
  • Introduction of specific profiles. Let me say for production or test connecting to MySQL and for your JpaTest an integration test profile without providing MySQL JDBC settings and let 'Autoconfiguration' do its job. E.g specify connection properties for MySQL in application-prod.properties and a separated configuration for an integration testing profile something like application-int-test.properties or so. Start your Test with -Dspring.profiles.active=int-test and you Spring Boot application with -Dspring.profiles.active=prod and you are good to go with properly separated environments. – claboran Mar 05 '18 at 08:41