Skip to Main Content
Spring Boot 2.0 Projects
book

Spring Boot 2.0 Projects

by Mohamed Shazin Sadakath
July 2018
Intermediate to advanced content levelIntermediate to advanced
336 pages
9h 23m
English
Packt Publishing
Content preview from Spring Boot 2.0 Projects

Testing Services

A Service with business logic needs to be tested to ensure it functions correctly. In order to do this, a Service like the following can be used:

@RunWith(MockitoJUnitRunner::class)@ActiveProfiles("dev")class MovieServiceTest {    @Mock    lateinit var movieRepository: MovieRepository;    lateinit var movieService: MovieService;

In the preceding test case for MovieService , MovieRepository is annotated with @Mock. During Service, test mocking is done using the Mockito library just to mock repository method invocations and verify the correct invocation. Consider the following code:

    @Before    fun setup() {        movieService = MovieService(movieRepository);    }    

The preceding code is used to create an instance of MovieService with a mocked ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Spring Boot 2.0

Mastering Spring Boot 2.0

Dinesh Rajput
Mockito for Spring

Mockito for Spring

Sujoy Acharya

Publisher Resources

ISBN: 9781789136159Supplemental Content