Introduction to the Unit Test tool C + + Test

Source: Internet
Author: User

C + + Test is a tool produced by Parasoft company to automate unit tests for C + + source code. It can carry out three kinds of test to the source code: White box test, black box test and regression work test.

White box test

C + + Test analyzes source code for all classes, and tests the member functions (including: public, protected, and private types) for all of them. The test method is to determine whether the function can be handled correctly when an illegal parameter is entered. (Record command) The software automatically generates test cases for specified files, classes, or functions in this state.

Black box test

The source code is not parsed and is only tested against the public interface functions of the class. (Play command)

In this state, the software does not automatically generate test cases, but rather runs directly into the test cases that are currently in the Test Case editor (added manually).

Regression work test

Re-test with the original test case after modifying the source code. (Play command)

It is recommended to use the Record command to execute the White box test first, let the software automatically generate the corresponding test case according to the function, then add some test cases according to the need, and then execute the black box test again through the play command.

Example One

Suppose we want to test the member function of the following class: int mode2 (int nparam), the software automatically generates the following 6 test cases for us when we do the White box test:

Nparam = 1, 0,-1, 2147483647,-2147483647, 230

It can be seen that the generation of software test cases is mainly to test some boundary values, such as the maximum value, minimum value, 0, and so on.

Example Two

Suppose we want to test the member functions of a class such as void strcpy (char* dest, Char const * SRC), the software automatically generates the following 9 test cases:

(1) dest = NULL, src = null

(2) Dest = "Ypqkij!u_", src = NULL

(3) Dest = "", src = NULL

(4) Dest = NULL, src = "h) zn9b"

(5) Dest = "Bsmc,/i=zi6ct}px", src = "Hci{bep (J")

(6) Dest = "", src = "% i?~tnon"

(7) Dest = NULL, src = ""

(8) Dest = "($MN <n;^", src = ""

(9) Dest = "", src = ""

As we can see, if our code is implemented without special handling of various possible situations, especially boundary conditions, it is easy to discover these potential problems through c++test. In addition, for some special test cases, we can also create test cases by hand. In addition, the use of C + + test can also help us to check the coding of the program, to determine whether the code specification is strictly developed.

Use

C + + test is easy to use, that is, for a VC project to carry out a comprehensive test, you can only a C/E + + source files for testing.

In the trial found that if the project is relatively large, it is best not to directly to a project automated testing, but should be a file one by one to test, otherwise can cause the program to die. Because it is developed using Java technology, it is best to use a faster machine.

Related Article

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.