Skip to content

Unit tests for esp-idf wrapper components #101

Description

@Barabas5532

Most ESP-IDF APIs are written in C, so googletest can't be used to mock them. We have to use link time substitution to mock the C APIs. Some options:

  • Wrap up the C API in a C++ API which can be mocked with googletest. This would be tightly coupled to the low level ESP-IDF component, unlike the wrapper which abstract ESP-IDF away. Then we can test the higher layer by mocking this low level wrapper. Even if we did this, then we might want to test the low level wrapper in some way, so this is not a solution.
  • https://github.com/meekrosoft/fff to mock the methods. The mock generation macros don't work in C++, and if used with C, then we can't easily test the wrapper's API which is C++.
  • https://cpputest.github.io/ seems easy enough, just have to use link time substitution on the C API
  • http://www.throwtheswitch.org/ceedling automates generating the mock C functions and also includes methods to set up expectations on calls. Might be easier to get going than cpputest.

https://stackoverflow.com/questions/14233853/c-unit-testing-and-stubbing-a-3rd-party-c-library

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions