JUnit Source Code Analysis (2)

xiaoxiao2021-03-06  47

Only we have mentioned the contents of the JUnit.EXTENTIONS package TestSetup. Let's take a look at the structure of the entire package.

Prompt in order to introduce the functions of each class in the package. ActiveTestSuite has improved TestSuite so that each Test is in a separate thread and only the entire test is ended only. ExceptionTestCase is an improvement to TestCase, which can easily determine if the test class throws an expected exception. And the rest of the three classes, you look at it is designed to use decorative model. Among them, TestDecorator makes the use rules for specific decorative classes, and RepeatedTest and TestSetup are specific implementation decoration classes.

What is the decorative mode in what an extensestSuite and ExcetionTestSTSTSE? The reason is that the decorative mode requires recursion similar to the combined mode in structure. For existing TestCase and TestSuite, directly inherit them is much more and simple to build a new recursive structure; and these enhancements are just for TestCase or TestSuite. The class with decorative mode is expanded is that the enhancement of their function is for any TEST implementation. If you do not use the decorative mode, you should write the subclasses separately for TestCase, TestSuite, and other TESTs. So use decorative models can be very cleverly solve this problem.

Let's introduce a junit.runner package. It has been mentioned that for JUnit users, it can be said to be completely transparent, and this package provides JUnit's own test class load. Below is the relationship diagram of all classes in the package.

Nothing, it is to use the reflex mechanism to load the test class, and the operation of reading the Properties file. If you want to learn the application of the reflex mechanism and try to write your own class loader, you can read the source code of this section.

The remaining three packages are not introduced, and most of the content is the Drawing of GUI (Of course, the JUnit.Textui package is except).

The observer mode is also used in JUnit to complete the automatic update of the unit test results (see me for details on the observer mode).

In this way,

Junit

The overall framework has a comprehensive understanding. Overall, each package is clear, designing the necessary design models in design to enhance scalability and reuse, and it is worth learning and reference.

转载请注明原文地址:https://www.9cbs.com/read-47575.html

New Post(0)