mirror of
https://github.com/google/googletest.git
synced 2024-12-27 10:11:03 +08:00
Googletest export
Add links to "sampleK_unittest.cc" examples. Fix some broken docs crosslinks. PiperOrigin-RevId: 261169561
This commit is contained in:
parent
da28d30191
commit
8756ef9058
@ -177,7 +177,8 @@ Example usage:
|
|||||||
To customize the default action for a particular method of a specific mock
|
To customize the default action for a particular method of a specific mock
|
||||||
object, use `ON_CALL()`. `ON_CALL()` has a similar syntax to `EXPECT_CALL()`,
|
object, use `ON_CALL()`. `ON_CALL()` has a similar syntax to `EXPECT_CALL()`,
|
||||||
but it is used for setting default behaviors (when you do not require that the
|
but it is used for setting default behaviors (when you do not require that the
|
||||||
mock method is called). See go/prefer-on-call for a more detailed discussion.
|
mock method is called). See [here](cook_book.md#UseOnCall) for a more detailed
|
||||||
|
discussion.
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
ON_CALL(mock-object, method(matchers))
|
ON_CALL(mock-object, method(matchers))
|
||||||
@ -332,8 +333,8 @@ The `argument` can be either a C string or a C++ string object:
|
|||||||
|
|
||||||
`ContainsRegex()` and `MatchesRegex()` take ownership of the `RE` object. They
|
`ContainsRegex()` and `MatchesRegex()` take ownership of the `RE` object. They
|
||||||
use the regular expression syntax defined
|
use the regular expression syntax defined
|
||||||
[here](http://go/gunit-advanced-regex). `StrCaseEq()`, `StrCaseNe()`, `StrEq()`,
|
[here](advanced.md#regular-expression-syntax). `StrCaseEq()`, `StrCaseNe()`,
|
||||||
and `StrNe()` work for wide strings as well.
|
`StrEq()`, and `StrNe()` work for wide strings as well.
|
||||||
|
|
||||||
#### Container Matchers
|
#### Container Matchers
|
||||||
|
|
||||||
@ -658,20 +659,20 @@ which must be a permanent callback.
|
|||||||
: : be any copyable value. Available since :
|
: : be any copyable value. Available since :
|
||||||
: : v1.1.0. :
|
: : v1.1.0. :
|
||||||
|
|
||||||
#### Using a Function, Functor, Lambda, or Callback as an Action
|
#### Using a Function, Functor, or Lambda as an Action
|
||||||
|
|
||||||
In the following, by "callable" we mean a free function, `std::function`,
|
In the following, by "callable" we mean a free function, `std::function`,
|
||||||
functor, lambda, or `google3`-style permanent callback.
|
functor, or lambda.
|
||||||
|
|
||||||
| | |
|
| | |
|
||||||
| :---------------------------------- | :------------------------------------- |
|
| :---------------------------------- | :------------------------------------- |
|
||||||
| `f` | Invoke f with the arguments passed to |
|
| `f` | Invoke f with the arguments passed to |
|
||||||
: : the mock function, where f is a :
|
: : the mock function, where f is a :
|
||||||
: : callable (except of google3 callback). :
|
: : callable. :
|
||||||
| `Invoke(f)` | Invoke `f` with the arguments passed |
|
| `Invoke(f)` | Invoke `f` with the arguments passed |
|
||||||
: : to the mock function, where `f` can be :
|
: : to the mock function, where `f` can be :
|
||||||
: : a global/static function or a functor. :
|
: : a global/static function or a functor. :
|
||||||
| `Invoke(object_pointer, | Invoke the {method on the object with |
|
| `Invoke(object_pointer, | Invoke the method on the object with |
|
||||||
: &class\:\:method)` : the arguments passed to the mock :
|
: &class\:\:method)` : the arguments passed to the mock :
|
||||||
: : function. :
|
: : function. :
|
||||||
| `InvokeWithoutArgs(f)` | Invoke `f`, which can be a |
|
| `InvokeWithoutArgs(f)` | Invoke `f`, which can be a |
|
||||||
|
@ -695,4 +695,4 @@ For example, in some tests we may not care about how many times `GetX()` and
|
|||||||
In gMock, if you are not interested in a method, just don't say anything about
|
In gMock, if you are not interested in a method, just don't say anything about
|
||||||
it. If a call to this method occurs, you'll see a warning in the test output,
|
it. If a call to this method occurs, you'll see a warning in the test output,
|
||||||
but it won't be a failure. This is called "naggy" behavior; to change, see
|
but it won't be a failure. This is called "naggy" behavior; to change, see
|
||||||
[The Nice, the Strict, and the Naggy](#NiceStrictNaggy).
|
[The Nice, the Strict, and the Naggy](cook_book.md#NiceStrictNaggy).
|
||||||
|
@ -91,9 +91,9 @@ trace, you'll gain insights on why the expectations you set are not met.
|
|||||||
|
|
||||||
If you see the message "The mock function has no default action set, and its
|
If you see the message "The mock function has no default action set, and its
|
||||||
return type has no default value set.", then try
|
return type has no default value set.", then try
|
||||||
[adding a default action](http://go/gmockguide#DefaultValue). Due to a known
|
[adding a default action](for_dummies.md#DefaultValue). Due to a known issue,
|
||||||
issue, unexpected calls on mocks without default actions don't print out a
|
unexpected calls on mocks without default actions don't print out a detailed
|
||||||
detailed comparison between the actual arguments and the expected arguments.
|
comparison between the actual arguments and the expected arguments.
|
||||||
|
|
||||||
### My program crashed and `ScopedMockLog` spit out tons of messages. Is it a gMock bug?
|
### My program crashed and `ScopedMockLog` spit out tons of messages. Is it a gMock bug?
|
||||||
|
|
||||||
|
@ -399,7 +399,8 @@ and you're ready to go.
|
|||||||
|
|
||||||
### More String Assertions
|
### More String Assertions
|
||||||
|
|
||||||
(Please read the [previous](#AssertThat) section first if you haven't.)
|
(Please read the [previous](#asserting-using-gmock-matchers) section first if
|
||||||
|
you haven't.)
|
||||||
|
|
||||||
You can use the gMock
|
You can use the gMock
|
||||||
[string matchers](../../googlemock/docs/cheat_sheet.md#string-matchers) with
|
[string matchers](../../googlemock/docs/cheat_sheet.md#string-matchers) with
|
||||||
@ -1407,7 +1408,10 @@ Please note that `INSTANTIATE_TEST_SUITE_P` will instantiate *all* tests in the
|
|||||||
given test suite, whether their definitions come before or *after* the
|
given test suite, whether their definitions come before or *after* the
|
||||||
`INSTANTIATE_TEST_SUITE_P` statement.
|
`INSTANTIATE_TEST_SUITE_P` statement.
|
||||||
|
|
||||||
You can see sample7_unittest.cc and sample8_unittest.cc for more examples.
|
You can see [sample7_unittest.cc] and [sample8_unittest.cc] for more examples.
|
||||||
|
|
||||||
|
[sample7_unittest.cc]: ../samples/sample7_unittest.cc "Parameterized Test example"
|
||||||
|
[sample8_unittest.cc]: ../samples/sample8_unittest.cc "Parameterized Test example with multiple parameters"
|
||||||
|
|
||||||
### Creating Value-Parameterized Abstract Tests
|
### Creating Value-Parameterized Abstract Tests
|
||||||
|
|
||||||
@ -1446,7 +1450,7 @@ returns the value of `testing::PrintToString(GetParam())`. It does not work for
|
|||||||
|
|
||||||
NOTE: test names must be non-empty, unique, and may only contain ASCII
|
NOTE: test names must be non-empty, unique, and may only contain ASCII
|
||||||
alphanumeric characters. In particular, they
|
alphanumeric characters. In particular, they
|
||||||
[should not contain underscores](https://github.com/google/googletest/blob/master/googletest/docs/faq.md#why-should-test-suite-names-and-test-names-not-contain-underscore)
|
[should not contain underscores](faq.md#why-should-test-suite-names-and-test-names-not-contain-underscore)
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
class MyTestSuite : public testing::TestWithParam<int> {};
|
class MyTestSuite : public testing::TestWithParam<int> {};
|
||||||
@ -1555,7 +1559,9 @@ TYPED_TEST(FooTest, DoesBlah) {
|
|||||||
TYPED_TEST(FooTest, HasPropertyA) { ... }
|
TYPED_TEST(FooTest, HasPropertyA) { ... }
|
||||||
```
|
```
|
||||||
|
|
||||||
You can see sample6_unittest.cc
|
You can see [sample6_unittest.cc] for a complete example.
|
||||||
|
|
||||||
|
[sample6_unittest.cc]: ../samples/sample6_unittest.cc "Typed Test example"
|
||||||
|
|
||||||
## Type-Parameterized Tests
|
## Type-Parameterized Tests
|
||||||
|
|
||||||
@ -1630,7 +1636,7 @@ that type directly without `::testing::Types<...>`, like this:
|
|||||||
INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, int);
|
INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, int);
|
||||||
```
|
```
|
||||||
|
|
||||||
You can see `sample6_unittest.cc` for a complete example.
|
You can see [sample6_unittest.cc] for a complete example.
|
||||||
|
|
||||||
## Testing Private Code
|
## Testing Private Code
|
||||||
|
|
||||||
@ -1998,7 +2004,9 @@ You can do so by adding one line:
|
|||||||
```
|
```
|
||||||
|
|
||||||
Now, sit back and enjoy a completely different output from your tests. For more
|
Now, sit back and enjoy a completely different output from your tests. For more
|
||||||
details, you can read this sample9_unittest.cc
|
details, see [sample9_unittest.cc].
|
||||||
|
|
||||||
|
[sample9_unittest.cc]: ../samples/sample9_unittest.cc "Event listener example"
|
||||||
|
|
||||||
You may append more than one listener to the list. When an `On*Start()` or
|
You may append more than one listener to the list. When an `On*Start()` or
|
||||||
`OnTestPartResult()` event is fired, the listeners will receive it in the order
|
`OnTestPartResult()` event is fired, the listeners will receive it in the order
|
||||||
@ -2023,7 +2031,9 @@ handle `OnTestPartResult()` *before* listeners that can generate failures. This
|
|||||||
ensures that failures generated by the latter are attributed to the right test
|
ensures that failures generated by the latter are attributed to the right test
|
||||||
by the former.
|
by the former.
|
||||||
|
|
||||||
We have a sample of failure-raising listener sample10_unittest.cc
|
See [sample10_unittest.cc] for an example of a failure-raising listener.
|
||||||
|
|
||||||
|
[sample10_unittest.cc]: ../samples/sample10_unittest.cc "Failure-raising listener example"
|
||||||
|
|
||||||
## Running Test Programs: Advanced Options
|
## Running Test Programs: Advanced Options
|
||||||
|
|
||||||
|
@ -263,7 +263,7 @@ If necessary, you can continue to derive test fixtures from a derived fixture.
|
|||||||
googletest has no limit on how deep the hierarchy can be.
|
googletest has no limit on how deep the hierarchy can be.
|
||||||
|
|
||||||
For a complete example using derived test fixtures, see
|
For a complete example using derived test fixtures, see
|
||||||
[googletest sample](https://github.com/google/googletest/blob/master/googletest/samples/sample5_unittest.cc)
|
[sample5_unittest.cc](../samples/sample5_unittest.cc).
|
||||||
|
|
||||||
## My compiler complains "void value not ignored as it ought to be." What does this mean?
|
## My compiler complains "void value not ignored as it ought to be." What does this mean?
|
||||||
|
|
||||||
|
@ -51,26 +51,34 @@ of misunderstanding these.
|
|||||||
Historically, googletest started to use the term _Test Case_ for grouping
|
Historically, googletest started to use the term _Test Case_ for grouping
|
||||||
related tests, whereas current publications including the International Software
|
related tests, whereas current publications including the International Software
|
||||||
Testing Qualifications Board ([ISTQB](http://www.istqb.org/)) and various
|
Testing Qualifications Board ([ISTQB](http://www.istqb.org/)) and various
|
||||||
textbooks on Software Quality use the term _[Test
|
textbooks on Software Quality use the term _[Test Suite][istqb test suite]_ for
|
||||||
Suite](http://glossary.istqb.org/search/test%20suite)_ for this.
|
this.
|
||||||
|
|
||||||
The related term _Test_, as it is used in the googletest, is corresponding to
|
The related term _Test_, as it is used in the googletest, is corresponding to
|
||||||
the term _[Test Case](http://glossary.istqb.org/search/test%20case)_ of ISTQB
|
the term _[Test Case][istqb test case]_ of ISTQB and others.
|
||||||
and others.
|
|
||||||
|
|
||||||
The term _Test_ is commonly of broad enough sense, including ISTQB's definition
|
The term _Test_ is commonly of broad enough sense, including ISTQB's definition
|
||||||
of _Test Case_, so it's not much of a problem here. But the term _Test Case_ as
|
of _Test Case_, so it's not much of a problem here. But the term _Test Case_ as
|
||||||
was used in Google Test is of contradictory sense and thus confusing.
|
was used in Google Test is of contradictory sense and thus confusing.
|
||||||
|
|
||||||
googletest recently started replacing the term _Test Case_ by _Test Suite_ The
|
googletest recently started replacing the term _Test Case_ with _Test Suite_.
|
||||||
preferred API is TestSuite*. The older TestCase* API is being slowly deprecated
|
The preferred API is *TestSuite*. The older TestCase API is being slowly
|
||||||
and refactored away
|
deprecated and refactored away.
|
||||||
|
|
||||||
So please be aware of the different definitions of the terms:
|
So please be aware of the different definitions of the terms:
|
||||||
|
|
||||||
Meaning | googletest Term | [ISTQB](http://www.istqb.org/) Term
|
| Meaning | googletest Term | [ISTQB](http://www.istqb.org/) |
|
||||||
:----------------------------------------------------------------------------------- | :---------------------- | :----------------------------------
|
: : : Term :
|
||||||
Exercise a particular program path with specific input values and verify the results | [TEST()](#simple-tests) | [Test Case](http://glossary.istqb.org/search/test%20case)
|
| :---------------- | :---------------------- | :----------------------------- |
|
||||||
|
| Exercise a | [TEST()](#simple-tests) | [Test Case][istqb test case] |
|
||||||
|
: particular : : :
|
||||||
|
: program path with : : :
|
||||||
|
: specific input : : :
|
||||||
|
: values and verify : : :
|
||||||
|
: the results : : :
|
||||||
|
|
||||||
|
[istqb test case]: http://glossary.istqb.org/en/search/test%20case
|
||||||
|
[istqb test suite]: http://glossary.istqb.org/en/search/test%20suite
|
||||||
|
|
||||||
## Basic Concepts
|
## Basic Concepts
|
||||||
|
|
||||||
@ -235,9 +243,8 @@ of two wide strings fails, their values will be printed as UTF-8 narrow strings.
|
|||||||
**Availability**: Linux, Windows, Mac.
|
**Availability**: Linux, Windows, Mac.
|
||||||
|
|
||||||
**See also**: For more string comparison tricks (substring, prefix, suffix, and
|
**See also**: For more string comparison tricks (substring, prefix, suffix, and
|
||||||
regular expression matching, for example), see
|
regular expression matching, for example), see [this](advanced.md) in the
|
||||||
[this](https://github.com/google/googletest/blob/master/googletest/docs/advanced.md)
|
Advanced googletest Guide.
|
||||||
in the Advanced googletest Guide.
|
|
||||||
|
|
||||||
## Simple Tests
|
## Simple Tests
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user