From the course: Complete Guide To Java Testing with JUnit 5 & Mockito
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Verify arguments with argument captors
From the course: Complete Guide To Java Testing with JUnit 5 & Mockito
Verify arguments with argument captors
- [Instructor] Argument captors provide an alternative approach for verifying your methods are called with the correct arguments. Instead of merely specifying conditions that the arguments should match, argument captors allow you to capture and inspect the actual arguments passed. This enables more detailed inspections of the arguments after the method call, making your tests more robust. Let's take a look at an example. Here we have a test that verifies some processing for a transaction. In our verification, we use an argument matcher to verify the third argument is a timestamp. Let's modify this to use an argument captor so we can see the actual value of the timestamp passed. To start off, we'll create an argument captor for our timestamp. This is done as part of the method, but we can also make this a field if we want to use the captor in multiple tests. If we make it a field, we can leverage the captor annotation. The captor annotation creates an argument captor instance that can…
Contents
-
-
-
-
-
-
-
-
(Locked)
Set up Mockito1m 40s
-
(Locked)
Mocking basics3m 17s
-
(Locked)
How to mock an object in Java2m 32s
-
(Locked)
Stub a method with Mockito3m
-
(Locked)
Verify an interaction with Mockito3m 49s
-
(Locked)
Verify arguments with argument matchers3m 13s
-
(Locked)
Verify arguments with argument captors5m 7s
-
(Locked)
Challenge: Test a library management system1m 32s
-
(Locked)
Solution: Test a library management system7m 6s
-
(Locked)
-
-
-