Tohid Makari
Tohid Makari

Reputation: 2484

when to use spring boot test and when to use Mockito?

when to use spring boot test whe to use Mockito? which one is suitable for unit test and which one for integration test?

Upvotes: 0

Views: 1477

Answers (1)

rieckpil
rieckpil

Reputation: 12021

It's not really an either-or question. You need and use both for writing unit and integration tests with Spring Boot.

When writing unit tests to verify, e.g. a business logic in isolation, you can solely rely on JUnit and Mockito.

Depending on how you define the word unit, you might also include tests that use Spring Boot Test slice annotations (e.g. @WebMvcTest) as unit tests. In such cases, you also work with Mockito as you mock other collaborators with @MockBean (annotation from Spring Boot, which creates a Mockito mock).

It might make sense to start with this overview of testing Spring Boot applications.

Upvotes: 2

Related Questions