Skip to content

Adding support of googletest / googlemock #83689

Open
@anobli

Description

@anobli
Contributor

Introduction

Zephyr already provide an awesome test suite that work very well with C but seems more limited with C++.
It would be great having googletest and googlemock available in Zephyr for testing complex C++ libraries or applications.

Problem description

I guess the major issue is mocking a C++ class is not easily doable and is quite limited with the current test suite.
In addition, gmock and gtest are widely used, supporting it in zephyr would simplify writing C++ tests.

Proposed change

Create a googletest external module that could be used to write tests using gmock and gtest.

Proposed change (Detailed)

I would to update googletest to support Zephyr, update it to make it an external module.
I guess that Zephyr OS support itself should accepted upstream, not sure about the external module changes so we may have to fork googletest.
I would also adds some unit tests example written with gtest to demonstrate how using it with twister, and also, to make sure the test suite is working correctly.
There is also some changes to do in gtest harness (I need to check if this still the case on master) . I am not sure why, it was not able to parse the tests output.

Dependencies

This would add a new component, googletest to zephyr. I think we could make it optional since I think it should only downloaded if this is actually used by a project. Ideally, all the required changes in googletest would be upstream. If this is not the case, we may to fork it.

Alternatives

I have looked for some alternatives for testing / mocking C++ code but I have not found anything already supported by Zephyr.
In addition, I am working on projects already using it.

Activity

added
RFCRequest For Comments: want input from the community
on Jan 8, 2025
github-actions

github-actions commented on Jan 8, 2025

@github-actions

Hi @anobli! We appreciate you submitting your first issue for our open-source project. 🌟

Even though I'm a bot, I can assure you that the whole community is genuinely grateful for your time and effort. 🤖💙

JeffWelder

JeffWelder commented on Apr 20, 2025

@JeffWelder

I flipped you a DM on discord about my attempts to support showing these tests in the VSCode C++ Testmate extension. 😀

kartben

kartben commented on Apr 20, 2025

@kartben
Collaborator

@anobli Twister already has a gTest harness, have you tried it?

anobli

anobli commented on Apr 23, 2025

@anobli
ContributorAuthor

@kartben Yes, I have been using the gTest harness, and it was working. The only issue I had was with the timings printed by gTest (the harness doesn't handle them).
I should have precised it, but, the the issue not really with gTest but really with gmok.
IIRC, gmock only build for native target, but, it doesn't build for any qemu or real target.
I have opened a PR for it, but, it take a while:
google/googletest#4692

kartben

kartben commented on Apr 23, 2025

@kartben
Collaborator

@yperess might be able to help

added theissue type on May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFCRequest For Comments: want input from the communityarea: Test FrameworkIssues related not to a particular test, but to the framework instead

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @kartben@henrikbrixandersen@anobli@JeffWelder

        Issue actions

          Adding support of googletest / googlemock · Issue #83689 · zephyrproject-rtos/zephyr