A pure C mocking library
Перейти к файлу
Dan Cristoloveanu e04fc00651
Update dependencies (#375)
2024-11-05 15:31:51 -08:00
.github/policies Remove auto approve bot dismissal policy (#317) 2023-10-18 21:47:02 -07:00
build Anpo 03 oct 2024 update deps (#366) 2024-10-04 00:54:37 +00:00
configs remove INC_FOLER, add_mock_library (#367) 2024-10-11 08:20:55 -07:00
deps Update dependencies (#375) 2024-11-05 15:31:51 -08:00
devdoc Add some more Windows types (as needed) (#325) 2023-12-13 12:48:19 -08:00
doc Lock factory to allow using umock in multithreaded tests (#177) 2020-11-25 19:41:30 -08:00
inc/umock_c Avoid a C4505 on windows (#374) 2024-10-25 12:18:30 -07:00
src Use c-logging for UMOCK_LOG (#355) 2024-06-12 09:03:48 -07:00
tests Avoid a C4505 on windows (#374) 2024-10-25 12:18:30 -07:00
.gitignore better .gitignore (#249) 2022-05-13 14:37:31 -07:00
.gitmodules uses non azure deps (#173) 2020-10-30 13:24:51 -07:00
CMakeLists.txt have a better function to generate the mocked file content (#370) 2024-10-13 21:40:59 -07:00
LICENSE Add LICENSE file 2019-03-29 19:10:24 -07:00
SECURITY.md Microsoft mandatory file (#262) 2022-08-09 22:08:01 -07:00
readme.md Change skip_unittests to run_unittests 2016-12-05 11:19:11 -08:00
set_vld_vars.bat Switch build to msazure 2019-12-27 19:27:56 -08:00

readme.md

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

umock_c

umock_c is a C mocking library.

Setup

Build

  • Clone umock_c by:
git clone --recursive https://github.com/Azure/umock-c.git
  • Create a cmake folder under the root of umock-c

  • Switch to the cmake folder and run

cmake ..

If you would like to use installed (by CMake) versions of packages already on your machine:

cmake -Duse_installed=ON ../
  • Build the code for your platform (msbuild for Windows, make for Linux, etc.) by executing in the cmake folder:
cmake --build .

To install umock_c:

cmake -Duse_installed=ON ../

On Linux:

sudo make install

On Windows:

msbuild /m INSTALL.vcxproj

This requires that ctest and testrunnerswitcher are both installed (through CMake) on your machine.

Building tests

In order to build the tests use the run_unittests cmake option:

cmake .. -Drun_unittests:bool=ON

Example

Ever wanted to write something like this in C as a test?

TEST_FUNCTION(my_first_test)
{
    // arrange
    STRICT_EXPECTED_CALL(test_dependency_1_arg(42))
        .SetReturn(44)
        .IgnoreAllArguments();

    // act
    int result = function_under_test();

    // assert
    ASSERT_ARE_EQUAL(int, 44, result);
    ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
}

umock_c has way more features than this simple example!

Dependencies

  • 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.
  • umock_c uses cmake (https://cmake.org/) to generate build files.
  • umock_c uses testrunnerswitcher to allow switching between ctest and CppUnitTest for Windows.

Documentation

Complete documentation is available here.