|
1 | 1 | # GoogleTest |
| 2 | +- Ref: https://google.github.io/googletest/ |
2 | 3 | - GoogleTest helps you write better C++ tests. |
3 | | -## 1. Basic Concepts |
4 | | -- **assertions:** the statememts that check whether a condition is true. The result can be: |
5 | | - - success |
6 | | - - nonfatal failure |
7 | | - - fatal failure |
8 | | -- **test suite:** that contains one or many tests. |
9 | | -- **text fixture:** the class contain test suite used for multiple tests to share common objects and subroutines. |
| 4 | +- Basic Concepts: |
| 5 | + - **Assertions:** the statememts that check whether a condition is true. The result can be: |
| 6 | + - success |
| 7 | + - nonfatal failure |
| 8 | + - fatal failure |
| 9 | + - **Test Suite:** that contains one or many tests. |
| 10 | + - **Text fixture:** the class contain test suite used for multiple tests to share common objects and subroutines. |
| 11 | + |
| 12 | +## 1. Assertions: |
| 13 | +- **ASSERT_** generates fatal failures and **abort** the current function. |
| 14 | +- **EXPECT_** generates nonfatal failures and don't abort the current function. (Preferred) |
| 15 | +- To provide a custom failure message, simply stream it into the macro using **`<<`** |
| 16 | +- Ref: https://google.github.io/googletest/reference/assertions.html |
10 | 17 |
|
11 | 18 | ## 2. Test Fixtures: Using the Same Data Configuration for Multiple Tests |
12 | 19 | - To create a fixture class: |
|
16 | 23 | - write a default destructor or `TearDown()` function to release resources. |
17 | 24 | - use `TEST_F(TestFixtureClassName, TestName)` instead of `TEST()` |
18 | 25 |
|
19 | | ->All documentation is covered in the official github repo. The primer documentation also covers a lot of information regarding the test macros. You could use the following summary and the examples linked to choose what you want to use. (https://stackoverflow.com/questions/58600728/what-is-the-difference-between-test-test-f-and-test-p) |
| 26 | +> All documentation is covered in the official github repo. The primer documentation also covers a lot of information regarding the test macros. You could use the following summary and the examples linked to choose what you want to use. (https://stackoverflow.com/questions/58600728/what-is-the-difference-between-test-test-f-and-test-p) |
20 | 27 |
|
21 | 28 | - **TEST()** is useful when you want to write unit tests for static or global functions or simple classes. |
22 | 29 | - **TEST_F()** is useful when you need access to objects and subroutines in the unit test. |
@@ -100,4 +107,5 @@ int main(int argc, char **argv) { |
100 | 107 | +) first, you use some simple macros to describe the interface you want to mock, and they will expand to the implementation of your mock class; |
101 | 108 | +) next, you create some mock objects and specify its expectations and behavior using an intuitive syntax; |
102 | 109 | +) then you exercise code that uses the mock objects. gMock will catch any violation to the expectations as soon as it arises. |
| 110 | +
|
103 | 111 | TBD https://google.github.io/googletest/gmock_for_dummies.html |
0 commit comments