4 years, 9 months ago.

Unit test and stub classes from mbed-os

Let's consider following example

simple snipet

#include "mbed.h"

void blink(mbed::DigitalOut LED, int delay_ms){
// the body of this funciton does not mater but letrs asume that assign operator of LED is called multiple times, and sleep method with paramter delay_ms.
}

As you can see, I pass class that is member of the mbed-os. I would like to create object of the same type for test porpouses. To do so I need a stub.

How do I do it? is there any tool, that can create stubs (compatible with google mock) or do I have to do it manualy ?

Up to this point I created file "mbed.h" in test directory, and defined there the classes that I need to stub, but I do not like this approach, because my stubs, are no logner the same type as in the original code. So could you show me how should it be done?

I have seen the github.com/mbed-os/UNITTEST project, but those examples show how to use google mock on classes that I created. And I need to stub classes from mbed.

Or should I wrapp every type provided by mbed by my own interface?, but this will result in a lot of pointles code ( made only for tests to be run)

Be the first to answer this question.