-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Hands-On Microservices with Kotlin
By :

Testing complex systems can be challenging, especially when we are dealing with dependencies. If our software depends on an external system such as a database or another service backend, it's hard to make our test without predicting the results from something that is not in our control. We can use a mechanism to prevent this from affecting us. We can use mocks that will mimic the expected output from another system.
Making our tests repeatable is a must in modern software development. Mocking will allow us to always get the same result, regardless of how many times, or in what order, our tests run.
Let's go back to our previous test, where we tested our CustomerController
in our CustomerControllerTest
class, and let's review our /customers
test:
@Test fun `we should GET a list of customers`() { mockMvc.perform(get("/customers")) .andExpect(status().isOk) .andExpect(jsonPath("\$").isArray) .andExpect(jsonPath("\$[0].id").value(1)) .andExpect...