课程: Complete Guide To Java Testing with JUnit 5 & Mockito
今天就学习课程吧!
今天就开通帐号,24,600 门业界名师课程任您挑!
Verify no (or a set number of) interactions
课程: Complete Guide To Java Testing with JUnit 5 & Mockito
Verify no (or a set number of) interactions
- [Instructor] When testing interactions between objects, you can verify your code by ensuring a given method is called the expected number of times. Traditional testing approaches often don't have the ability to enforce a constraint like this, but with Mockito, we have a suite of tools that can help us. Mockito offers a method called Times, and it allows you to specify the exact number of times a method should be called. Let's take a look at an example. Here, we have a user service test class. Once fully implemented, it will test whether we can create, update, and delete users. The first test method ensures that when we create a user, we save that user in the data repository. By default, the Verify method verifies the given method was called one time with the stated arguments. In this case, username one, which is Alice. If we use the Times method, we'd write something like this: "times(1)." Here, we verify the user repository is called one time with the given username. It gives us…
内容
-
-
-
-
-
-
-
-
-
(已锁定)
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 秒
-
(已锁定)
-
-