JUnit Framework First Experience

Source: Internet
Author: User

Just contact with software testing, JUnit is not very understanding, so first Baidu a bit of its concept.

JUnit is a unit test framework for the Java language. JUnit has its own expanded biosphere. Most Java development environments have integrated JUnit as a unit test tool.

JUnit is a regression testing framework (regression testing framework) written by Erich Gamma and Kent Beck. JUnit testing is a programmer's test, the so-called white-box test, because the programmer knows how the software being tested accomplishes the function and what functions are done. JUnit is a set of frameworks that inherit the TestCase class and can be automatically tested with JUnit.

In addition, JUnit is a highly recommended tool in extreme programming and refactoring (refactor) because it can greatly improve the efficiency of development in the case of automated unit testing, but it also takes a lot of time and effort to write test code.

The advantages can be mainly divided into:

A. Extreme Programming

Requiring you to write tests before you write code that forces you to think about the functionality and logic of your code before you write code, otherwise the code you write is very unstable, and you need to maintain both the test code and the actual code, and the workload will be greatly increased. So in extreme programming, the basic process is this: the concept of writing test code----write code--test, and write test and write code are incremental, write a little bit, in the code after writing, if you find the problem can quickly trace the cause of the problem, Reduces the difficulty of error correction for regression errors.

B. Refactoring

The benefits are similar to extreme programming, because refactoring also requires a little bit of measurement to reduce the time consumed by regression errors.

Actual test:

I also did the actual operation according to the prompt steps.

    1. First create a new project called Junit_test, write a calculator class, this is a simple implementation of the subtraction, square, root of the calculator class, and then to the unit test these functions.
    2. Introduce the JUNIT4 unit test package to this project: Right-click on the item and click "Properties". In the pop-up Properties window, first select "Java Build Path" on the left, then select "Libraries" tab on the right, then click "Add Library ..." button on the far right. Then select JUNIT4 in the New Popup dialog box and click OK.
    3. Generate JUnit Test framework: In Eclipse's Package Explorer, right-click the pop-up menu and select JUnit test case. After the relevant configuration is completed, the following can be generated:

Although the tests were not very successful (the test class was a fork), I had a rough idea of how to use it after a simple attempt. Expect to be able to use JUnit for programming, testing to bring convenience ~

Simple Tutorial Study site: http://tech.sina.com.cn/s/2010-01-18/14081218926.shtml

JUnit Framework First Experience

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.