LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Getting started with the Unit Test Framework

Solved!
Go to solution

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!

0 Kudos
Message 1 of 12
(934 Views)

Did Setup and Teardown not serve your needs? Could you show an example why you can't test a state machine? 

0 Kudos
Message 2 of 12
(923 Views)

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.

0 Kudos
Message 3 of 12
(897 Views)

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.

 

  • No support for maps/sets
  • VIs inside a class fail with some error about incorrect Interface inheritance (the class doesn't have any). Presumably a bug because some newly created classes are fine, but others have this problem.
  • Test Cases sometimes get deleted when opening an .lvtest file. Presumably a bug.
  • LabVIEW cannot rename an .lvtest file. Also a bug since the Rename option is there but doesn't work.

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.

0 Kudos
Message 4 of 12
(771 Views)

There are several alternatives to the UTF available through VIPM (https://www.vipm.io/search/?q=unit+test).  Many of these are open-source.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 5 of 12
(768 Views)

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.

0 Kudos
Message 6 of 12
(767 Views)

Thanks @crossrulz - do you (or anyone else) recommend one in particular?

0 Kudos
Message 7 of 12
(766 Views)

Caraya has the most installs.  I played with it a little and it seems like a good unit tester.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 8 of 12
(731 Views)
Solution
Accepted by topic author OneOfTheDans

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

Senior Software Development Engineer
Certified LabVIEW Architect and LabVIEW Champion
https://theLonelyAnt.com


0 Kudos
Message 9 of 12
(702 Views)

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.

0 Kudos
Message 10 of 12
(652 Views)