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