Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
googletest
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
googletest
Commits
b4676595
Commit
b4676595
authored
Jun 19, 2019
by
Gennadiy Civil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Incremental doc changes in preparation for doc sync
parent
152c7dfd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
15 deletions
+21
-15
primer.md
googletest/docs/primer.md
+21
-15
No files found.
googletest/docs/primer.md
View file @
b4676595
...
...
@@ -164,7 +164,7 @@ you'll get a compiler error. We used to require the arguments to support the
`<<`
is supported, it will be called to print the arguments when the assertion
fails; otherwise googletest will attempt to print them in the best way it can.
For more details and how to customize the printing of the arguments, see
gMock
[
recipe
](
../../googlemock/docs/cook_book.md#teaching-google-mock-how-to-print-your-values
)
.).
[
documentation
](
https://github.com/google/googletest/blob/master/googlemock/docs/cook_book.md#teaching-gmock-how-to-print-your-values
)
These assertions can work with a user-defined type, but only if you define the
corresponding comparison operator (e.g.
`==`
,
`<`
, etc). Since this is
...
...
@@ -214,12 +214,18 @@ as `ASSERT_EQ(expected, actual)`, so lots of existing code uses this order. Now
The assertions in this group compare two
**C strings**
. If you want to compare
two
`string`
objects, use
`EXPECT_EQ`
,
`EXPECT_NE`
, and etc instead.
| Fatal assertion | Nonfatal assertion | Verifies |
| ------------------------------- | ------------------------------- | -------------------------------------------------------- |
|
`ASSERT_STREQ(str1, str2);`
|
`EXPECT_STREQ(str1, str2);`
| the two C strings have the same content |
|
`ASSERT_STRNE(str1, str2);`
|
`EXPECT_STRNE(str1, str2);`
| the two C strings have different contents |
|
`ASSERT_STRCASEEQ(str1, str2);`
|
`EXPECT_STRCASEEQ(str1, str2);`
| the two C strings have the same content, ignoring case |
|
`ASSERT_STRCASENE(str1, str2);`
|
`EXPECT_STRCASENE(str1, str2);`
| the two C strings have different contents, ignoring case |
| Fatal assertion | Nonfatal assertion | Verifies |
| ----------------------- | ----------------------- | ---------------------- |
|
`ASSERT_STREQ(str1, | `
EXPECT_STREQ(str1, | the two C strings have |
: str2);
` : str2);`
: the same content :
|
`ASSERT_STRNE(str1, | `
EXPECT_STRNE(str1, | the two C strings have |
: str2);
` : str2);`
: different contents :
|
`ASSERT_STRCASEEQ(str1, | `
EXPECT_STRCASEEQ(str1, | the two C strings have |
: str2);
` : str2);`
: the same content, :
: : : ignoring case :
|
`ASSERT_STRCASENE(str1, | `
EXPECT_STRCASENE(str1, | the two C strings have |
: str2);
` : str2);`
: different contents, :
: : : ignoring case :
Note that "CASE" in an assertion name means that case is ignored. A
`NULL`
pointer and an empty string are considered
*different*
.
...
...
@@ -265,7 +271,7 @@ For example, let's take a simple integer function:
int
Factorial
(
int
n
);
// Returns the factorial of n
```
A test
cas
e for this function might look like:
A test
suit
e for this function might look like:
```
c++
// Tests factorial of 0.
...
...
@@ -285,8 +291,8 @@ TEST(FactorialTest, HandlesPositiveInput) {
googletest groups the test results by test suites, so logically-related tests
should be in the same test suite; in other words, the first argument to their
`TEST()`
should be the same. In the above example, we have two tests,
`HandlesZeroInput`
and
`HandlesPositiveInput`
, that belong to the same test
suite
`FactorialTest`
.
`HandlesZeroInput`
and
`HandlesPositiveInput`
, that belong to the same test
suite
`FactorialTest`
.
When naming your test suites and tests, you should follow the same convention as
for
[
naming functions and
...
...
@@ -319,14 +325,14 @@ When using a fixture, use `TEST_F()` instead of `TEST()` as it allows you to
access objects and subroutines in the test fixture:
```
c++
TEST_F
(
Test
Suit
eName
,
TestName
)
{
TEST_F
(
Test
Fixtur
eName
,
TestName
)
{
...
test
body
...
}
```
Like
`TEST()`
, the first argument is the test suite name, but for
`TEST_F()`
this
must be the name of the test fixture class. You've probably guessed:
`_F`
is for
fixture.
Like
`TEST()`
, the first argument is the test suite name, but for
`TEST_F()`
this must be the name of the test fixture class. You've probably guessed:
`_F`
is for
fixture.
Unfortunately, the C++ macro system does not allow us to create a single macro
that can handle both types of tests. Using the wrong macro causes a compiler
...
...
@@ -411,7 +417,7 @@ The above uses both `ASSERT_*` and `EXPECT_*` assertions. The rule of thumb is
to use
`EXPECT_*`
when you want the test to continue to reveal more errors after
the assertion failure, and use
`ASSERT_*`
when continuing after failure doesn't
make sense. For example, the second assertion in the
`Dequeue`
test is
=ASSERT_NE(nullptr, n)=
, as we need to dereference the pointer
`n`
later, which
`ASSERT_NE(nullptr, n)`
, as we need to dereference the pointer
`n`
later, which
would lead to a segfault when
`n`
is
`NULL`
.
When these tests run, the following happens:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment