课程: Complete Guide To Java Testing with JUnit 5 & Mockito
今天就学习课程吧!
今天就开通帐号,24,600 门业界名师课程任您挑!
Spy on real objects with Mockito
课程: Complete Guide To Java Testing with JUnit 5 & Mockito
Spy on real objects with Mockito
- [Instructor] With a good understanding of Mockito and what mocking means, we can begin to dive into some more advanced concepts. One of these advanced concepts is partial mocking through something called spying. Partial mocking allows you to create an object that combines real method calls and stubbed methods. This can be really useful when you want to test certain parts of an object's behavior while controlling or isolating other parts. In Mockito, this can be achieved using a spy. Let's take a look at an example. Here we have a payment service that uses an account service as a dependency. Instead of mocking the account service, we use the spy annotation so we can use most of its behavior and only mock certain parts. To stub the account service, we use the doReturn method because it ensures that the real method is not called during the stubbing process. It makes it clear that this is the part of the spy we're mocking and avoids any unintended side effects. Everything else is pretty…
内容
-
-
-
-
-
-
-
-
-
(已锁定)
Spy on real objects with Mockito4 分钟 31 秒
-
(已锁定)
Test exception handling with Mockito2 分钟 10 秒
-
(已锁定)
Test void methods with Mockito5 分钟 10 秒
-
(已锁定)
Verify no (or a set number of) interactions5 分钟 1 秒
-
(已锁定)
GetAllValues with ArgumentCaptor5 分钟 1 秒
-
(已锁定)
Test asynchronous code with Mockito3 分钟 17 秒
-
(已锁定)
Mock a static method with Mockito3 分钟 15 秒
-
(已锁定)
Challenge: Test an ordering service1 分钟 2 秒
-
(已锁定)
Solution: Test an ordering service8 分钟 21 秒
-
(已锁定)
-
-