JUnit Source Analysis (ii)

Source: Internet
Author: User
Tags reflection

In the above we have mentioned the contents of the Junit.extentions package Testsetup. Take a look at the structure of the whole package.











Briefly introduce the functions of each class in the package below. Activetestsuite has improved the testsuite so that each test runs in a separate thread and only ends when all threads are finished. Exceptiontestcase is an improvement on testcase, which makes it easy to determine whether the test class throws the expected exception. And the remaining three classes, probably you can see is using the decorative pattern to design. Which testdecorator for the specific decorative class set up the use of rules, repeatedtest and Testsetup is the specific implementation of the decorative class.



So why is Activetestsuite and exceptiontestcase in Extentions pack not using decorative mode? The reason is that the decorative pattern requires a recursive structure that resembles a combination pattern. For existing testcase and testsuite, it is much quicker and simpler to inherit them directly than to build a new recursive structure, and these enhancements are only directed at TestCase or Testsuite. Classes that are extended using decorative patterns are different from these, and their enhancements are implemented for any test. If you do not use the same functionality as the decorative pattern, you write subclasses for TestCase, Testsuite, and other later test implementations. Therefore, the use of decorative mode can be very clever to solve this problem.







Below is an introduction to the next Junit.runner package. As mentioned above, it can be said to be completely transparent to the JUnit user, which provides JUnit's own test class loading. The following is the diagram of all the classes in the package.









There is nothing to talk about, is to use the reflection mechanism to load the test class, as well as read the properties file operation. If you want to learn the application of the reflection mechanism can read this part of the source code.







The remaining three packages are not covered here, and most of the content is GUI drawing (except Junit.textui packages, of course).







JUnit also uses the Observer pattern to automate the unit test results (see my article on Observer mode for details).


In this way, there is a comprehensive understanding of JUnit's overall framework. In general, the Division of labor is clear, the design adopted the necessary design patterns to enhance the scalability and reuse, it is worth learning and reference.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.