| 1 |
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [[email protected]](mailto:[email protected]) with any additional questions or comments. |
| 2 |
|
| 3 |
# umock_c |
| 4 |
|
| 5 |
umock_c is a C mocking library. |
| 6 |
|
| 7 |
## Setup |
| 8 |
|
| 9 |
### Build |
| 10 |
|
| 11 |
- Clone umock_c by: |
| 12 |
|
| 13 |
``` |
| 14 |
git clone --recursive https://github.com/Azure/umock-c.git |
| 15 |
``` |
| 16 |
|
| 17 |
- Create a cmake folder under the root of umock-c |
| 18 |
|
| 19 |
- Switch to the cmake folder and run |
| 20 |
``` |
| 21 |
cmake .. |
| 22 |
``` |
| 23 |
|
| 24 |
If you would like to use installed (by CMake) versions of packages already on your machine: |
| 25 |
|
| 26 |
``` |
| 27 |
cmake -Duse_installed=ON ../ |
| 28 |
``` |
| 29 |
|
| 30 |
- Build the code for your platform (msbuild for Windows, make for Linux, etc.) by executing in the cmake folder: |
| 31 |
|
| 32 |
``` |
| 33 |
cmake --build . |
| 34 |
``` |
| 35 |
|
| 36 |
### To install umock_c: |
| 37 |
|
| 38 |
``` |
| 39 |
cmake -Duse_installed=ON ../ |
| 40 |
``` |
| 41 |
On Linux: |
| 42 |
``` |
| 43 |
sudo make install |
| 44 |
``` |
| 45 |
On Windows: |
| 46 |
``` |
| 47 |
msbuild /m INSTALL.vcxproj |
| 48 |
``` |
| 49 |
|
| 50 |
_This requires that ctest and testrunnerswitcher are both installed (through CMake) on your machine._ |
| 51 |
|
| 52 |
### Building tests |
| 53 |
|
| 54 |
In order to build the tests use the *run_unittests* cmake option: |
| 55 |
|
| 56 |
``` |
| 57 |
cmake .. -Drun_unittests:bool=ON |
| 58 |
``` |
| 59 |
|
| 60 |
## Example |
| 61 |
|
| 62 |
Ever wanted to write something like this in C as a test? |
| 63 |
|
| 64 |
```c |
| 65 |
TEST_FUNCTION(my_first_test) |
| 66 |
{ |
| 67 |
// arrange |
| 68 |
STRICT_EXPECTED_CALL(test_dependency_1_arg(42)) |
| 69 |
.SetReturn(44) |
| 70 |
.IgnoreAllArguments(); |
| 71 |
|
| 72 |
// act |
| 73 |
int result = function_under_test(); |
| 74 |
|
| 75 |
// assert |
| 76 |
ASSERT_ARE_EQUAL(int, 44, result); |
| 77 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 78 |
} |
| 79 |
``` |
| 80 |
|
| 81 |
umock_c has way more features than this simple example! |
| 82 |
|
| 83 |
## Dependencies |
| 84 |
|
| 85 |
- umock_c uses ctest as test runner (https://github.com/Azure/azure-ctest.git). ctest is a C test runner that can be run on many platforms as it does not make use of compiler/platform specific code and thus it is easily portable. |
| 86 |
- umock_c uses cmake (https://cmake.org/) to generate build files. |
| 87 |
- umock_c uses testrunnerswitcher to allow switching between ctest and CppUnitTest for Windows. |
| 88 |
|
| 89 |
## Documentation |
| 90 |
|
| 91 |
Complete documentation is available [here](doc/umock_c.md). |