mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-09 07:34:44 +02:00
Updated Getting the source code (markdown)
@@ -64,7 +64,7 @@ If we change the factorial function to take and return unsigned long instead (as
|
||||
|
||||
Although this was a simple test it's been enough to demonstrate a few things about how Catch is used. Let's take moment to consider those before we move on.
|
||||
|
||||
1. All we did was #include one header and we got everything - even an implementation of main() that will respond to command line arguments. You can only do this in one implementation file, for (hopefully) obvious reasons. Once you have more than one file with unit tests in you'll want to just #include "catch.hpp" instead. Usually it's a good idea to have a dedicated implementation file that just #include's "catch_with_main.hpp" as your entry point. You can also provide your own implementation of main and drive Catch yourself.
|
||||
1. All we did was #include one header and we got everything - even an implementation of main() that will [respond to command line arguments](https://github.com/philsquared/Catch/wiki/Command-line). You can only do this in one implementation file, for (hopefully) obvious reasons. Once you have more than one file with unit tests in you'll want to just #include "catch.hpp" instead. Usually it's a good idea to have a dedicated implementation file that just #include's "catch_with_main.hpp" as your entry point. You can also provide your own implementation of main and drive Catch yourself.
|
||||
2. We introduce test cases with the TEST_CASE macro. This macro takes two arguments - a hierarchical test name (forward slash separated, by convention) and a free-form description. The test name should be unique - and ideally will logically group related tests together like folders in a file system. You can run sets of tests by specifying a wildcarded test name.
|
||||
3. The name and description arguments are just strings. We haven't had to declare a function or method - or explicitly register the test case anywhere. Behind the scenes a function with a generated name is defined for you, and automatically registered using static registry classes. By abstracting the function name away we can name our tests without the constraints of identifier names.
|
||||
4. We write our individual test assertions using the REQUIRE macro. Rather than a separate macro for each type of condition we express the condition naturally using C/C++ syntax. Behind the scenes a simple set of expression templates captures the left-hand-side and right-hand-side of the expression so we can display the values in our test report. As we'll see later there _are_ other assertion macros - but because of this technique the number of them is drastically reduced.
|
||||
|
Reference in New Issue
Block a user