Win a copy of High Performance Python for Data Analytics this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
  • salvin francis
  • Frits Walraven
  • Piet Souris

Testing and SpingBootTest

Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys, I've few questions about unit and integration tests with Spring framework.

Lets suppose I've a simple architecture, made by controllers, services and repositories and I want to use Spring to make some tests with the specific mocks and annotations.
This is what I suppose to use for each layer:

Testing repositories -> @DataJpaTest (H2 in-mem database)
Testing services -> @Mock and @InjectMocks (Mockito library)
Testing controllers -> @WebMvcTest and @MockBean (@MockBean for mocking services)

As you can se I didn't find out a reason to use @SpringBootTest and bootstrap the entire Spring Context.

So, my questions are:

- What's the purpose of the annotation @SpringBootTest and when I should use it bootstrapping the entire application context?
- What if I need to test a specific component that's not a service/controller/repository? Should I use @SpringBootTest just for the specific class(es) I need to test and avoiding to bootstrap the entire context? (IE to test a mapping component)
- How can I perform an end to end test without mocking any component (so a real integration test)? Is it usually required as unit testing single layers?

Thanks for your help.
A lot of people cry when they cut onions. The trick is not to form an emotional bond. This tiny ad told me:
the value of filler advertising in 2020
    Bookmark Topic Watch Topic
  • New Topic