You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: index.markdown
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -85,7 +85,7 @@ For Windows users, the above work with cygwin. There are also several MS VC++ pr
85
85
86
86
## Where to find more information
87
87
88
-
* If you have any question, check out the [Google Groups](https://groups.google.com/forum/?fromgroups#!forum/cpputest)
88
+
* If you have any questions, check out the [Google Groups](https://groups.google.com/forum/?fromgroups#!forum/cpputest)
89
89
* The source is at the [main github page](https://github.com/cpputest/cpputest)
90
90
* You can report bugs or features at [the issues page](https://github.com/cpputest/cpputest/issues)
91
91
* You can follow [CppUTest on twitter](https://twitter.com/CppUTest)
@@ -127,7 +127,7 @@ int main(int ac, char** av)
127
127
}
128
128
{% endhighlight %}
129
129
130
-
For more information, We'd recommend to [read the manual](http://www.cpputest.org) or, even better, check some [existing tests](https://github.com/cpputest/cpputest/tree/master/tests) such as [SimpleStringTest](https://github.com/cpputest/cpputest/blob/master/tests/SimpleStringTest.cpp) or (a bit more complicated) [MemoryLeakDetectorTest](https://github.com/cpputest/cpputest/blob/master/tests/MemoryLeakDetectorTest.cpp) or the [mocking tests](https://github.com/cpputest/cpputest/blob/master/tests/CppUTestExt/TestMockSupport.cpp) or just check out the [Cheat Sheet](https://github.com/cpputest/cpputest/blob/master/tests/CheatSheetTest.cpp)
130
+
For more information, We'd recommend [reading the manual](http://www.cpputest.org) or, even better, check some [existing tests](https://github.com/cpputest/cpputest/tree/master/tests) such as [SimpleStringTest](https://github.com/cpputest/cpputest/blob/master/tests/SimpleStringTest.cpp) or (a bit more complicated) [MemoryLeakDetectorTest](https://github.com/cpputest/cpputest/blob/master/tests/MemoryLeakDetectorTest.cpp) or the [mocking tests](https://github.com/cpputest/cpputest/blob/master/tests/CppUTestExt/TestMockSupport.cpp) or just check out the [Cheat Sheet](https://github.com/cpputest/cpputest/blob/master/tests/CheatSheetTest.cpp)
131
131
132
132
## Related projects
133
133
@@ -141,4 +141,4 @@ Prerequisites:
141
141
142
142
## Authors and Contributors
143
143
144
-
CppUTest has had many contributions from its users. We can't remember all, but we appreciate it a lot!. Much of the original code was written by Michael Feathers (based on CppUnit Lite). The current main maintainers are [@jwgrenning](https://github.com/jwgrenning) and [@basvodde](https://github.com/basvodde)
144
+
CppUTest has had many contributions from its users. We can't remember all, but we appreciate it a lot! Much of the original code was written by Michael Feathers (based on CppUnit Lite). The current main maintainers are [@jwgrenning](https://github.com/jwgrenning) and [@basvodde](https://github.com/basvodde)
To write your first test, all you need is a new cpp file with a TEST_GROUP and a TEST, like:
36
36
{% highlight c++ %}
37
+
#include "CppUTest/TestHarness.h"
38
+
37
39
TEST_GROUP(FirstTestGroup)
38
40
{
39
41
};
@@ -60,6 +62,8 @@ One of the key design goals in CppUTest is to make it *very easy* to add and rem
60
62
Of course, in order to get it to run, you'll need to create a main. Most of the mains in CppUTest are very similar. They typically are in an AllTests.cpp file and look like this:
(The last flags is only needed when you want to use extensions such as mocking)
114
+
(The last flag is only needed when you want to use extensions such as mocking)
111
115
112
116
<aid="test_macros"> </a>
113
117
@@ -144,9 +148,9 @@ The failure of one of these macros causes the current test to immediately exit:
144
148
145
149
<aid="setup_teardown"> </a>
146
150
147
-
*CHECK_EQUALS Warning:*
151
+
*CHECK_EQUAL Warning:*
148
152
149
-
CHECK_EQUAL(expected, actual) can produce misleading error reports as it will evaluate expected and actual more than ones. THis especially leads to confusions when used with mocks. This happens if the mock function expects to be called exactly once, since the macro needs to evaluate the actual expression more than once. The problem does not occur with type specific checks (e.g. LONGS_EQUAL()), so it is recommended to use them if possible. Instead of:
153
+
CHECK_EQUAL(expected, actual) can produce misleading error reports as it will evaluate expected and actual more than ones. This especially leads to confusions when used with mocks. This happens if the mock function expects to be called exactly once, since the macro needs to evaluate the actual expression more than once. The problem does not occur with type specific checks (e.g. LONGS_EQUAL()), so it is recommended to use them if possible. Instead of:
150
154
151
155
{% highlight c++ %}
152
156
CHECK_EQUAL(10, mock_returning_11())
@@ -266,7 +270,7 @@ These are added by default when you use the CppUTest Makefile helpers.
266
270
267
271
### Turning memory leak detection off and on
268
272
269
-
If you want to disable the memory leak detection (because you got too much memory leaks?) then you can do so in several ways. However, it is strongly recommended to keep the memory leak detector on and fix your memory leaks (and your static initialization issues) as this tends to lead to higher quality code.
273
+
If you want to disable the memory leak detection (because you have too many memory leaks?) then you can do so in several ways. However, it is strongly recommended to keep the memory leak detector on and fix your memory leaks (and your static initialization issues) as this tends to lead to higher quality code.
270
274
271
275
You can turn the memory leak detection completely off by adding this to your main:
272
276
@@ -316,7 +320,7 @@ Now the call to the compiler needs to be -include MyOwnNewMacros.h and this will
316
320
317
321
### Conflicts with my own overload!
318
322
319
-
This one is harder (and luckily less common). You can solve this the same way as the conflict in STL, but its probably better to use a finer grained control. So, instead you can temporary disable the new macros, overload operator new, enable the new macro again. This can be done with the following code:
323
+
This one is harder (and luckily less common). You can solve this the same way as the conflict in STL, but it's probably better to use a finer grained control. So, instead you can temporary disable the new macros, overload operator new, enable the new macro again. This can be done with the following code:
320
324
321
325
{% highlight c++ %}
322
326
class NewDummyClass
@@ -608,7 +612,7 @@ The most important line to add is the GTestConvertor. Make sure you define the C
608
612
609
613
## Running Google Tests in CppUTest
610
614
611
-
People feel wonderfully religious about unit testing tools. Of course, we feel strongly that CppUTest beats other tools when you actually test-drive your software. But unfortunately, people still use tools like GoogleTest (which is actually not as bad as e.g. CppUnit). It is unlikely that we're going to convince people to use CppUTest instead, so therefore we've written some integration code where you can actually link google test and CppUTest tests together in one binary (with the CppUTest test runner). THis also gives you some additional benefits:
615
+
People feel wonderfully religious about unit testing tools. Of course, we feel strongly that CppUTest beats other tools when you actually test-drive your software. But unfortunately, people still use tools like GoogleTest (which is actually not as bad as e.g. CppUnit). It is unlikely that we're going to convince people to use CppUTest instead, so therefore we've written some integration code where you can actually link google test and CppUTest tests together in one binary (with the CppUTest test runner). This also gives you some additional benefits:
612
616
613
617
* You get memory leak detection over your google tests...
Copy file name to clipboardExpand all lines: mocking_manual.markdown
+12-12Lines changed: 12 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ layout: default
3
3
title: CppUTest Mocking Manual
4
4
---
5
5
6
-
CppUTest has support for building mocks. This document described the mocking support. A couple of design goals for the mocking support were:
6
+
CppUTest has support for building mocks. This document describes the mocking support. A couple of design goals for the mocking support were:
7
7
8
8
9
9
* Same design goals as CppuTest -- limited C++ set to make it well suitable for embedded soft.
@@ -67,7 +67,7 @@ The TEST(MockDocumentation, SimpleScenario) contains the recording of the expect
67
67
mock().expectOneCall("productionCode");
68
68
{% endhighlight %}
69
69
70
-
The call to mock() return the global MockSupport (more about that later) on which we can record our expectations. In this example, we'll call expectOneCall("productionCode") which... records an expectation for *one* call to a function called productionCode.
70
+
The call to mock() returns the global MockSupport (more about that later) on which we can record our expectations. In this example, we'll call expectOneCall("productionCode") which... records an expectation for *one* call to a function called productionCode.
71
71
72
72
The productionCode call is to show a call to whatever your real code is. The test ends with checking whether the expectations have been met. This is done with the:
73
73
@@ -88,7 +88,7 @@ void productionCode()
88
88
89
89
where we use MockSupport by calling mock() and then record the actual call to the productionCode function.
90
90
91
-
This scenario is quite common when using linker stubbing of e.g. a 3rd partly library.
91
+
This scenario is quite common when using linker stubbing of e.g. a 3rd party library.
92
92
93
93
If the call to productionCode wouldn't happen, then the test would fail with the following error message:
94
94
@@ -155,7 +155,7 @@ If the call to a wrong object happens, it would give the following error message
155
155
156
156
### Parameters
157
157
158
-
Of course, just checked whether a function is called is not particularly useful when we cannot check the parameters. Recording parameters on a function is done like this:
158
+
Of course, just checking whether a function is called is not particularly useful when we cannot check the parameters. Recording parameters on a function is done like this:
@@ -219,7 +219,7 @@ To remove the comparators, all you needs to do is call removeAllComparators, lik
219
219
mock().removeAllComparators();
220
220
{% endhighlight %}
221
221
222
-
Comparators sometimes lead to surprised, so a couple of warnings on its usage:
222
+
Comparators sometimes lead to surprises, so a couple of warnings on its usage:
223
223
224
224
*Warning 1:*
225
225
@@ -231,7 +231,7 @@ Comparators are *not* copied, instead it uses the exact instance as passed to th
231
231
232
232
* Pay extra attention to scope when using the MockPlugin
233
233
234
-
When using the MockPlugin (recommended), then its best to install the comparators via the MockPlugin or put them in global space. The checkExpectations will be called *after* teardown and if your comparator was destroyed in the teardown then this will cause a crash.
234
+
When using the MockPlugin (recommended), then it's best to install the comparators via the MockPlugin or put them in global space. The checkExpectations will be called *after* teardown and if your comparator was destroyed in the teardown then this will cause a crash.
* When an char, int, etc. array is passed to withOutputParameter, you must use the generic withOutputParameterReturning and provide the actual size of the array or only one element will be copied.
288
+
* When a char, int, etc. array is passed to withOutputParameter, you must use the generic withOutputParameterReturning and provide the actual size of the array or only one element will be copied.
289
289
290
290
<aid="return_values"> </a>
291
291
@@ -336,15 +336,15 @@ int value = mock().getData("importantValue").getIntValue();
Like return values. Setting data will not ever make a test fail but it provides support in building mock objects.
339
+
Like return values, setting data will not ever make a test fail but it provides support in building mock objects.
340
340
341
341
<aid="other_mock_support"> </a>
342
342
343
343
### Other MockSupport - ignoring, enabling, clearing, crashing
344
344
345
345
MockSupport offers a couple of other useful functions, which will be covered in this section.
346
346
347
-
Frequently, you only want to check a couple of calls in your test and ignore all the other calls. If you add expectOneCall for each of these calls, you're tests might become too large (though, it might be a smell that your test is indeed too large). One way to prevent this is the ignoreOtherCalls, like:
347
+
Frequently, you only want to check a couple of calls in your test and ignore all the other calls. If you add expectOneCall for each of these calls, your tests might become too large (though, it might be a smell that your test is indeed too large). One way to prevent this is the ignoreOtherCalls, like:
348
348
349
349
{% highlight c++ %}
350
350
mock().expectOneCall("foo");
@@ -373,7 +373,7 @@ int function () {
373
373
374
374
If you try to ignore it or disable the framework, it will explode. Why ? The return value is not defined so there is no way to define the return value of the mocked function.
375
375
376
-
To cases like these there is a series of return value functions that allows you to define a default return value, that will be returned when the mock function is ignored.
376
+
To cases like these there is a series of return value functions that allows you to define a default return value that will be returned when the mock function is ignored.
0 commit comments