Introduction to C ++ Unit Testing

Source: Internet
Author: User

The following describes in detail that C ++ unit testing does not support reflection. Therefore, some additional work must be done to let the framework know the existence of relevant content. CppUnit is registered with a macro. This method requires that we should consider using the corresponding macro for registration every time we add a test.

At this point, CxxTest is doing better, and there is a dedicated script to do this. Use this script to scan the self-written file, generate some new files, and complete this work. In terms of code performance and reliability, it is much better.

The only problem is that a script is introduced, which is generally written in some dynamic languages. Currently, CxxTest has Perl and Python scripts. However, due to the limitations of the C ++ language itself, this approach is quite good from the interface perspective.

Syntax
There is a C ++ Unit Test framework called TUT, short for Template Unit Test. As the name suggests, it is completed with a template. CppUnit and CxxTest both have a template ). With the development of the C ++ compiler, templates can be compiled smoothly in most cases.

However, do not forget that there is also an environment called embedded, where the compiler is basically primitive and the template is not necessarily able to be compiled smoothly. In addition, the template will bring about another problem, with the compilation time increasing. I believe that anyone with template programming experience will have a deep understanding of this. What does the compilation time increase mean? We will discuss it next.

  • Easy to play C ++ Builder
  • Exploring the mysteries of C ++
  • In-depth analysis of C ++ Language Learning
  • Introduction to C/C ++ concepts
  • Experience in C ++ code

Compilation Time
There is an agile practice called Test-Driven Development ). Test-driven development is based on unit testing. One goal of test-driven development is to achieve fast feedback. Therefore, from the perspective of the C ++ language, if the execution time is limited by the Code itself and cannot be shortened, we hope that the compilation time is as short as possible, in this way, we will not waste all our lives waiting for code compilation.

In addition to the template issue mentioned earlier, CppUnit will generate an executable file for all test compilations. What does this mean? Modifying almost any file will result in the re-generation of the file. As the target file increases, the process will grow. The modification range may be only one file ).

It seems a little long. Why can't this happen in Java? Because Java is dynamically connected, Java generation. class ends. Corresponding to C ++, this only completes the generation of the target file, and in C ++, We Have To further generate executable files.

In principle, C ++ unit testing can generate different executable files for different test files, but this does not involve the overall process, statistics show that the memory is insufficient, and this is usually not the case. Personally, I don't know much about these unit test frameworks. If the previous discussion has errors, I would like to welcome people of insight to point out.

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.