Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization 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 ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Testing and SpingBootTest

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • 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.
 
You will always be treated with dignity. Now, strip naked, get on the probulator and hold this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic