Explanation of various Error Methods for C ++ Unit Testing

Source: Internet
Author: User

C ++ unit testing is a standard, with different implementations and different understandings and implementation levels. C # and Java are controlled by commercial companies. There are few problems in this regard, but after reading this article, you will have many unexpected things.

I. unit testing can help customers locate errors more accurately and comprehensively, significantly improving software quality
Shows a test model for an application that contains many objects. A large elliptic represents an application, a small elliptic represents an object, and an arrow
Header indicates user input, and red star indicates potential errors.

In the integration test, in order to discover errors, we hope to continuously modify the input and cause interaction between objects to cause potential errors for an object, but this is undoubtedly difficult. Due to its difficulty, developers can only find errors by relying on the running failure of the application software. This makes it difficult to find the exact location of errors, and in fact there are still a large number of classes not tested.

The C ++ unit test provides a more effective method for identifying errors. It splits the smallest unit in the application, so that the test is closer to the error, as long as each minimal unit is tested independently, it is easy to make it possible to locate all program errors in an all-round and accurate manner.

Unit Testing can significantly reduce development time and costs while improving software quality
Because modifying a class at a higher level may change the design and functionality of multiple program components, the sooner the problem is discovered
◆ The more code you need to modify. When the amount of modified Code increases, the other two factors also increase:
◆ The time and cost required to modify each error introduce new error opportunities in the code

Research once and again proves that, with the delay of the detected time, the time required to discover software errors increases as the success rate increases. C ++ unit testing reduces the time and resources for discovering errors because it is easier to locate errors. Second, because you can discover and correct the errors after each class, you do not need to spend a lot of time re-understanding and exploration in the future.

Finally, the most important reason is that because of the interaction and associativity of classes, modifying a class at the unit level only affects the original class, avoid new errors caused by interactions between units. Therefore, unit testing can greatly reduce the development time and cost.

  • Advanced programmers describe operations on C ++ programs
  • Analysis of Visual C ++'s two complete Windows Applications
  • Explore the rich and colorful C ++ Technology
  • In-depth analysis of C ++ code compilation and statement Sequence
  • Programming in the Visual C ++ Environment

Based on the above information, unit testing looks like a panacea. If so, why does every C/C ++ developer not perform unit testing on every class immediately? As for the currently available technologies, unit testing for C/C ++ is a difficult, cumbersome, and time-consuming task. There is no good tool to automate this process, this makes many C/C ++ developers daunting.

The first step in executing the C ++ unit test is to make the target class measurable. This requires two tasks:
◆ Design a test driver for running the target class
◆ Design the pile functions. They create a test driver for any external resource return values referenced by the tested classes and create a new class, except for the original class of the C ++ unit test, it cannot be used for any other purpose. Test drive should have the following features:
◆ A standard setting and clearing method
◆ One method for selecting individual tests and all valid tests
◆ A mechanism for analyzing the output of expected or unexpected results)
◆ A standard error Report Form

To fully and correctly test the class, you need to design a test driver that can fully check the class under test; several modifications and rewriting are inevitable. Once a test driver is created, you must carefully check that it cannot contain any errors. An error in the C ++ unit test driver will damage this test, but you cannot test a class separately or test the driver itself.

If your class references any external resources that are not ready or inaccessible, such as external files, databases, and CORBA objects), you must create the corresponding pile function, their return values are similar to the actual external resources that should be returned.

When creating these functions, You need to select the return values of the functions, which will affect the execution path of the program:
◆ To test the functionality of the class, any path must be executed.
◆ Adequate paths to provide thorough test coverage

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.