6

I have a SpringBoot application with hibernate. In my tests I would like to disable any sort of db connection and configuration (tests don't have access to db). How should I do it ?

My test class is annotated with @SpringBootTest and has @Autowired properties. What's the proper annotation value to disable all db interactions ?

@SpringBootTest class MyTest { @Autowired .... } 
1
  • I have the same issue. have you found the solution? Commented Jun 16, 2022 at 4:41

2 Answers 2

1

This solved it for me:

@SpringBootTest @EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, HibernateJpaAutoConfiguration.class }) class MyServiceApplicationTests { @MockBean MyRepository repository; ... } 

check this link for the alternatives

Sign up to request clarification or add additional context in comments.

Comments

-1

You can use @TestPropertySource to override values in application.properties.

@TestPropertySource(locations="classpath:test.properties") 

A Quick Guide to @TestPropertySource

2 Comments

Spring data will be on spring context anyway, independent of your test property settings.
this don't solve the problem, your db beans are still use and they have no connection to db.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.