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

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

Title: Arduino Shared Code and Unit tests
Post by SandyBMX on May 30th, 2021 at 4: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 2:16pm
Was this a dumb question?

Title: Re: Arduino Shared Code and Unit tests
Post by Simon@Visual Micro on Jun 10th, 2021 at 2: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.

VS Arduino » Powered by YaBB 2.6.12!
YaBB Forum Software © 2000-2024. All Rights Reserved.