Mockito Junit Jupiter's Mock object verification method

Mockito Junit Jupiter's Mock object verification method Mockito is a popular simulation framework for Java for object simulation and verification in unit testing.Junit Jupiter is part of Junit 5, which is a test framework for writing unit testing.The combination of the two can easily simulate and verify the object behavior in the code. Mockito's verification function aims to ensure that the simulation objects used in tests are correctly called and interacting.The following is several common methods that use Mock objects to verify in the Mockito Junit Jupiter framework: 1. Verification method call Use the `verfy` method to verify whether the method of the simulation object is called.For example, suppose we want to verify whether the method of the simulation object's `dosomething () method is called once: // Create analog object MyClass myObject = Mockito.mock(MyClass.class); // The method of calling an analog object myObject.doSomething(); // Whether the verification method is called Mockito.verify(myObject, Mockito.times(1)).doSomething(); 2. Verification method parameters Mockito allows the parameters of the analog object method.For example, suppose we want to verify whether the method of the analog object's `addnumbers ()` method is called once with parameter 2 and 3: // Create analog object Calculator calculator = Mockito.mock(Calculator.class); // The method of calling an analog object calculator.addNumbers(2, 3); // Whether the verification method and parameters are called Mockito.verify(calculator).addNumbers(Mockito.eq(2), Mockito.eq(3)); 3. Verification method call order If the code involves the interaction of multiple objects, you can use the `Inrenter` class to verify the ordering order of the method.The following is a simple example: // Create analog object List<String> mockedList = Mockito.mock(List.class); // Create an organ object InOrder inOrder = Mockito.inOrder(mockedList); // Call on the simulation object mockedList.add("first"); mockedList.add("second"); // The call order of the verification method inOrder.verify(mockedList).add("first"); inOrder.verify(mockedList).add("second"); 4. The verification method is not called Sometimes it is necessary to verify that a method is not called.You can use the `VeriFyzerointeractionS` method to verify.For example: // Create analog object MyClass myObject = Mockito.mock(MyClass.class); // Do not call any method on the analog object // Whether the verification method is not called Mockito.verifyZeroInteractions(myObject); The above is just some common MOCK object verification methods in the Mockito Junit Jupiter framework.Using these verification methods can ensure the correct simulation and verification objects in the test, thereby increasing the reliability and quality of the code. Note: In order to be able to use Mockito and Junit Jupiter in the Maven project, you need to add corresponding dependencies to the POM.XML file, such as::: <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-core</artifactId> <version>3.12.4</version> <scope>test</scope> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>5.8.1</version> <scope>test</scope> </dependency> I hope this article will help you understand the verification method of the Mock object in the Mockito Junit Jupiter framework.