LUnit
LUnit is currently my preferred unit testing tool in LabVIEW. Here is why.
I've mentioned LUnit a few times lately and I have not done a good deep dive on it. LUnit is a unit testing tool for LabVIEW. It is an alternative to Caraya or VITester which seem to be the dominant test tools at the moment. It was created and maintained by Anton Sundqvist. He's really done a great job with it! I realized lately that not enough people know about it, so I wanted to help get the word out and encourage everyone to try it.
What do I like about it?
I do want to be clear that even though I prefer LUnit these days, Caraya and VI Tester both work and are used successfully by lots of people. If you prefer one of those tools, that's fine.
Here are just a few things I like about LUnit compared to using Caraya or VI Tester.
Faster
I find LUnit to be much faster than Caraya or VITester. Anton could probably tell you more about why. I believe it is doing some caching. All I can say is from my anecdotal experience it seems faster and more responsive.
Less Dependencies
VITester and Caraya both have a lot of dependencies. This may be what affects the speed. With LUnit there are a lot fewer dependencies.
More Organized Tests
This one is just a personal preference, but I like the structure provided by LUnit's adherence to the XUnit paradigm. If you are coming from VITester it will seem very familiar. Caraya on the other hand seems like the Wild West to me. There seem to be no real rules about organization. It's weird to me because in Python I prefer Pytest which is much more like Caraya. I will say for beginner programmers, Caraya is slightly easier to learn. You don't need to even think about classes or how you name your tests. You memorize one QuickDrop shortcut and that is all you need.
Better Failure Information
Lunit shows a lot more failure information than Caraya. It shows the expected and actual values which Caraya for some reason does not (at least out of the box - maybe there is a way to configure that.) To that point in LUnit the assertion inputs are labelled actual and expected. In Caraya and VITester it is just X and Y. I never can remember which one is supposed to be which.
Timing Analysis
LUnit has a built-in timing analysis tool. It tells you how long each test takes which allows you to identify slow tests.
Code Coverage
LUnit has a code coverage tool built in.
Advanced Comparisons
LUnit ships with some advanced comparisons like "Regex Matching", "Is an Element of" and "Match specific error". It's not quite as detailed as James McNally's VITAC for VITester and it's still really good.
LMock
Anton has built a mocking framework called LMock that integrates directly with LUnit. I haven't used it and the demo I saw was pretty impressive.
Inheritance for Test Cases
LUnit supports test case inheritance so you can run tests for parent classes on child classes. I don't make use of this and there is an example that ships with LUnit that looks interesting.
Parameterized Tests
LUnit has support for parameterized tests. This is a really useful feature that is missing in the other frameworks. If you find yourself writing one test case and then copying it many times and just changing a few input and output constants or if you find yourself putting a for loop around your code and the assertions, then this is a much better way. I used to find myself doing these things all the time and now I use parameterized tests. It results in less duplication of code and much nicer reporting when something fails.
Responsive Developer
Most importantly LUnit has a very responsive developer. He seems to be releasing new features and accepting pull requests quite regularly. I do know Francois does a good job with Caraya and he has been responsive when I've needed a few things in the past. VITester is another story. It pretty much seems like abandonware. It's actually a testament to the quality of it, that it is still going all these years without much maintenance. There are few things that are a little broken, like support for sets and maps. It's showing it's age. It's definitely time to move on from VITester if you are still hanging on. LUnit is the natural successor to VITester, since the syntax feels very familiar unlike Caraya which uses a different paradigm.
Need Help with Unit Testing?
If you want to learn how to take full advantage of LUnit and more about unit testing in general, check out our upcoming Unit Testing Workshop next week. It's not too late to get tickets.