Visual Micro
https://www.visualmicro.com/forums/YaBB.pl
Visual Micro >> Visual Studio 2017, 2019 >> Arduino Shared Code and Unit tests
https://www.visualmicro.com/forums/YaBB.pl?num=1622348948

Message started by SandyBMX on May 30th, 2021 at 5:29am

Title: Arduino Shared Code and Unit tests
Post by SandyBMX on May 30th, 2021 at 5:29am
Hello! This is a really neat project.  I was looking for an easy way to unit test some of my code and stumbled on this video:
https://www.youtube.com/watch?v=Pbpis0tdg3A

I followed all the steps to get set up but was unable to unit test any shared code that contained types or functions specific to the arduino platform like millis() or String (ya, I know).  Is that my failure, or is this some way to do this with mocking or otherwise?

Title: Re: Arduino Shared Code and Unit tests
Post by SandyBMX on Jun 10th, 2021 at 3:16pm
Was this a dumb question?

Title: Re: Arduino Shared Code and Unit tests
Post by Simon@Visual Micro on Jun 10th, 2021 at 3:33pm
Sorry we missed this post. It's a valid question.

Using the Unit testing as shown here, only C++ code which is not Arduino specific can be tested.

If your code received millis() as an unsigned long into the function/s, it is easier to then unit test by calling with a known set of values, or an incrementing loop in your test.

Its often easier to isolate the logic out to the unit testable projects, and then just call into it from Arduino, with its added hardware and platform tools.

Visual Micro » Powered by YaBB 2.5.2!
YaBB Forum Software © 2000-2021. All Rights Reserved.