A/C + + unit Test catch

Source: Internet
Author: User

1.catch Single File resource download: (Test proof 2017-year single file on it, 2010 need a package of documents, praise technical progress)

Https://raw.githubusercontent.com/philsquared/Catch/master/single_include/catch.hpp

Location of the 2.catch file

(1) Direct and tested C + + files are placed under a folder

(2) include plus search path

Include<>: First go to the system directory your change file, if not in the current directory to find.

Include "": "First look in the current directory, if not found, then to the system directory to find

Use of 3.catch

    •  1.  #define一个标识符和#include一个头文件。Add unit tests to multiple files and you just need to join #include "catch.hpp" . Only one implementation file #define CATCH_CONFIG_MAIN is added and #include "catch.hpp" is the best.
    • 2. TEST_CASE:宏引入测试用例。这个宏需要一个或两个参数,允许测试名自定义以及可选的一个或多个标签( the name of the test case needs to be unique, and you can test the settings by specifying a wildcard or label expression. The name and label of the parameter are just string types. We don't have to declare a function or method or register a test case with a display. The function name is automatically generated in the background and registered using the static registration class. We can name our tests arbitrarily by the abstract function name.
    • 3. REQUIRE write the test assertion using a macro.
    • 4. Each SECTION will be executed from the beginningTEST_CASE,当我们进入到每个section时,我们已经知道v的大小是5且容量大于等于5。为了确保达到这些这些要求,我们使用REQUIRE 强制进行限制。他们的工作机制是:SECTION中包含if语句,并将结果返回到Catch中以确定哪个section将会执行。TEST_CASE每运行一次会执行一个section,其他section直接跳过。下一次则执行下一个section,如此反复直到没有新的section。

A/C + + unit Test catch

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.