Code implementation to analyze the JUnit framework

Source: Internet
Author: User
Tags reflection

Introduction: This article describes the JUnit code implementation in detail, based on the demonstration of the code flow UML diagram, detailed analysis of JUnit's internal implementation code functions and mechanisms, and in the relevant design patterns where the combination of code to explain. In addition, the analysis process involves advanced features of the Java language such as Reflection.

Overview

As the test-driven development philosophy has become popular today, JUnit's core position in the field of test development is increasingly stable. Not only does Eclipse use JUnit as the default IDE integration component, but the various test frameworks based on JUnit are also widely used in the industry and are well received. While the introduction of JUnit book articles is more, most of them are for JUnit's specific application practices, but for JUnit's own mechanism, it stays in the shallow level of the framework module.

This article fully describes JUnit's detailed code implementation, and provides a detailed analysis of the functionality and mechanism of JUNIT's internal implementation code, based on a UML diagram of the code flow, and explains it in conjunction with code where relevant design patterns are involved. In addition, the analysis process involves advanced features of the Java language such as Reflection.

The reader of this article should be aware of JUnit's basic principles and various design patterns, mainly for the design, development and testing of Java-related technologies. For c++,c# programmers also have a good reference role.

Introduction to Junit

The concept and use of JUnit

JUnit is an open source unit testing framework written by Erich Gamma and Kent Beck. It is a white-box test, and as long as the class to be tested inherits the TestCase class, a series of JUnit mechanisms can be used to facilitate automated testing.

JUnit's design is streamlined and easy to learn, but the functionality is powerful, thanks to its built-in code structure. Erich Gamma is one of the famous GOF, so JUnit is deeply permeated with the idea of excellent design patterns. The API provided by JUnit allows you to write out the specific reusable unit test cases for test results, as well as the ability to run the unit test cases in batches. In a framework that has already been implemented, users can choose three ways to display test results, and the way they are displayed is extensible.

JUnit Fundamentals

A JUnit test contains the following elements:

Table 1. Test Case composition

Development Code Section Test Code Section Test Tools Section
Class A to be tested By extending TestCase or constructing testsuit methods

Write Test class B

A test run (testrunner) R, you can select a graphical interface or a text interface

Operation Steps:

Pass B through command-line or graphical interface selection to R,r to run the test automatically, and display the results.

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.