Detailed explanation of Java single test void type method

preface

When we learn Java, teachers or ordinary books say that there are eight basic types of Java. They are byte, int, short, long, float, double, char and Boolean. However, when I read thinking in Java, the Bible of Java, this morning, I found that the author put void on it when explaining the data type. So there are nine. Baidu, some books are also written. There are nine basic types of Java.

There are many void type methods in the service layer of Java, such as save *, update *. These methods only do some updates and do not have a return value. Their single test cannot be written according to the return value of the method, and only special methods can be used;

Environment of this method: mockito, TestNG

Method tested:

The void method you want to test is Java

Test method:

The method returned by void tests Java

As shown in the note, if two breakpoints are added, the last call line will be executed first during execution, and the stub of endpoint 2 will be executed during execution of endpoint 1. At this time, the input parameters of method execution can be obtained at breakpoint 2, and the input parameters can be assert verified to achieve the purpose;

New anwer is an interface with only one method, which is used to set the proxy execution entry for method calls

Implementation of doanswer in Java

When the code executes to "ruledao. Updateselective (rule);" When, the interceptor called for mock object will be triggered. In the interceptor, a dynamic agent will be created. The invocation of the dynamic agent is the method covered in new answer;

The two methods of interception and proxy are used to set and obtain the input and output parameters of mock object method. In this way, the execution class call inside the void method can be verified;

summary

The above is the whole content of this article. I hope the content of this article can bring some help to your study or work. If you have any questions, you can leave a message.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>