Search the courses, subjects, tracks, games and features, or jump straight to a page.
2 cards from this section. Quick, good the night before a test.
What annotation is used to create a mock object in Mockito?
Think about the purpose of the annotation; it creates something fake for testing.
How do you specify that a mock should return a specific value?
It involves setting a condition followed by the expected result.
What does the @Mock annotation do?
Recall the primary role of mocking in testing.
True or False: The verify method is used to define the behavior of a mock object.
Consider what verifying implies in the context of testing.
Design a unit test class that uses Mockito to test a UserService class that relies on a UserRepository mock. The test should verify that the findUser method returns the expected user when called.
Think about the dependencies and how to inject them appropriately into `UserService`.
In a service that calculates discounts, how would you use Mockito to mock the database layer that retrieves product prices? Write a test case demonstrating this.
Make sure you clarify the roles of the database layer and the service you're testing.
4 more questions in this section. Enroll free to practise them all.
Enroll free