01-26-2024 09:32 AM
Does anyone have a good example of how to use the Unit Test Framework in practice? I like the idea of automatic test coverage over my code, but don't know where to start.
Poking around the tool, I see how you could validate extremely basic VIs like simple calculations... but how do you test real code like device drivers, state machines, LVOOP, and GUI manipulation via VI Server?
Thanks for any insight!
Solved! Go to Solution.
01-26-2024 09:59 AM - edited 01-26-2024 10:00 AM
Did Setup and Teardown not serve your needs? Could you show an example why you can't test a state machine?
01-26-2024 10:26 AM
I guess I don't see the big picture of how this is supposed to work for anything other than bare-bones calculations.
Setup/Teardown - I just tried writing a new Setup VI that parses a Map into class private variables. The tool says Maps are an invalid type, so can't be used with them? So I need a different Setup VI for every test condition I want to run?
State Machine - (I don't have one per se, but in theory) assume the state machine is one VI, a loop that moves through states until some underlying hardware condition is met. Once UTF launches the state machine VI, there's no way to validate which states it moves through, and there's no way to trigger that external hardware condition, so the machine will never return.
I must be missing something fundamental.
01-30-2024 02:04 PM
Well, I've concluded NI's Unit Test Framework is only suitable for small, simple programs. I can see it being useful for math-heavy algorithms, but it's no good for validating general code.
I'm on the 2020 version, so maybe it has improved in the past few years. Maybe I'll try this again if we upgrade to the latest version of LabVIEW.
01-30-2024 02:21 PM
There are several alternatives to the UTF available through VIPM (https://www.vipm.io/search/?q=unit+test). Many of these are open-source.
01-30-2024 02:24 PM
Actually, I played with this a bit more. The Unit Test Framework cannot test any VIs using a Class if the project contains an Interface (even if the test and class don't use the Interface).
NI reported fixing a similar bug in 2022 Q3: Error Reported When Testing VIs in LabVIEW Interfaces. That bug should be added to the LabVIEW 2020 Unit Test Framework Toolkit Known Issues.
01-30-2024 02:25 PM
Thanks @crossrulz - do you (or anyone else) recommend one in particular?
01-31-2024 06:54 AM
Caraya has the most installs. I played with it a little and it seems like a good unit tester.
01-31-2024 05:31 PM
I like Caraya from JKI
I wrote up a bit of an overview of several different unit testing tools and their pros and cons on my blog - https://thelonelyant.com/labview-unit-testing-tools-overview/ - hopefully it might make it easier to pick one 🙂
Cheers
Brett
02-05-2024 11:12 AM
That's a great write-up, thanks for sharing! I noticed the article says you prefer VI Tester (back in 2020) but now you're liking Caraya more. Why the shift?
From reading about it, I also like Caraya's simplicity, but might find value in VI Tester holding my hand, since I'm not familiar with unit testing concepts yet.