Unit Testing Group

cancel
Showing results for 
Search instead for 
Did you mean: 

Best practices for Unit Testing

Hello all,

 

I am planning to use the Unit Test Framework (UTF) in my project to test some VIs. All the VIs include objects to be passed through them. Also, I want to integrate the tests with Jenkins. I wanted to know the best practices to be followed while writing a unit test (mainly for object-oriented LabVIEW VIs) and which testing framework can I choose for testing the VIs (As there are a couple of objects to be passed through the VIs, I am not sure which one would be best to test them). Please give me your thoughts on this.

 

Thanks in advance.

 

 

 

 

0 Kudos
Message 1 of 23
(5,415 Views)

Hi Bhargavi,

 

If you are using objects I would probably recommend avoiding NI UTF. To use objects with it requires writing custom tests for everything which can be a little cumbersome.

 

Of the other options I like VI Tester - it is all LabVIEW code so works well with objects and I have it integrated with Jenkins so that is possible. Not sure about Jenkins integration on others but I'm sure someone can let you know.


As far as best practices, the easiest thing I can do is point you to some of my blog posts 🙂 https://devs.wiresmithtech.com/blog/tag/unit-testing/

 

Cheers,

James

James Mc
========
CLA and cRIO Fanatic
My writings on LabVIEW Development are at devs.wiresmithtech.com
Message 2 of 23
(5,410 Views)

Hi Bhargavi,

 

another option is InstaCoverage: http://sine.ni.com/nips/cds/view/p/lang/hu/nid/216652

 

InstaCoverage is a new unit testing tool for LabVIEW code. It comes with a free trial.

 

Here is a Jenkins demonstrator which integrates InstaCoverage for an example LabVIEW project: https://build.incquerylabs.com/jenkins/job/instacoverage-ci-demonstrator/job/master/

 

A documentation of the example can be found here: https://github.com/IncQueryLabs/instacoverage-ci-demonstrator/wiki

 

Although the example code in the demonstrator is not object-oriented LabVIEW, InstaCoverage works for LVOOP too. The demo project of the tool (included in the installation package) is an object-oriented example. Above Jenkins example would look like pretty much the same with object-oriented code too.

 

In general UTF and InstaCoverage come handy if you want to measure code coverage. Also, they support explicit test configuration files (.lvtest and .instacov), which come handy when structuring your test projects. In other cases, VI tester can be a good choice too.

 

Peter

0 Kudos
Message 3 of 23
(5,400 Views)

Hello James,

 

Thanks for responding and pointing me to your blog posts, I will surely look into themSmiley Happy

 

Can you elaborate on the point "To use objects with it requires writing custom tests for everything which can be a little cumbersome"? It would be great if you could give an example and demonstrate why do we need to avoid NI UTF when using objects.

 

Thanks againSmiley Happy 

 

 

0 Kudos
Message 4 of 23
(5,400 Views)

Hi Peter,

 

Thanks for letting me know about the new unit testing tool(InstaCoverage):smileyhappy:

I also wanted to get clarified on a few things

1) Do you see any advantages in InstaCoverage against VI Tester? Which one would you prefer to use?

2) Why is NI Tester not a good choice? (Any reason for not even mentioning about NI Tester)

3) Please mention if you have faced any difficulties in using the VI Tester.

 

Thanks in advanceSmiley Happy

0 Kudos
Message 5 of 23
(5,389 Views)

Hi Bhargavi,

 

Sure. The NI UTF is designed to work on a connector pane, so you chose a VI and chose what to put in the connector pane.

 

This doesn't work with objects since they normally need some code to set them up since you can't enter the internal values on the connector pane. 

 

So instead you have to create a new VI with a cluster that you populated with pass/fail details. This works perfectly well but I found that this way of writing tests was easier in VI Tester than UTF.

 

Cheers,
James

James Mc
========
CLA and cRIO Fanatic
My writings on LabVIEW Development are at devs.wiresmithtech.com
0 Kudos
Message 6 of 23
(5,374 Views)

Hi Bhargavi,

 

I attach a table comparing different tools for unit testing LabVIEW code. It's an excerpt of a talk I will give tomorrow at NI VIP in Fürstenfeldbruck, Germany. 

 

Which tool is the best for you depends on your needs. Object-oriented code can be handled by all of them (with varying overhead as James also pointed out).  

 

I don't know NI Tester, what is it?

 

Peter

Message 7 of 23
(5,368 Views)

Hi Bhargavi,

 

Check out the pinned post on this forum at https://forums.ni.com/t5/Unit-Testing-Group/TS3370-Save-Time-and-Money-With-Unit-Testing/gpm-p/35287...

 

It is from a presentation I gave at NI Week 2014. Scroll down to the end, there is a video showing how to do custom tests for Unit Test Framework. Before that, there are different demonstrations using JKI VI Tester and Unit Test Framework. 

 

I need to go back and add the same demonstrations using Peter Bokor's InstaCoverage tool. Peter and his team at IncQueryLabs are doing a great job addressing all of the community concerns. Among them the fact that, as James noted, it is hard to test LVOOP code with UTF.

 

Regards,

Fab

For an opportunity to learn from experienced developers / entrepeneurs (Steve, Joerg, and Brian amongst them):
Check out DSH Pragmatic Software Development Workshop!

DQMH Lead Architect * DQMH Trusted Advisor * Certified LabVIEW Architect * Certified LabVIEW Embedded Developer * Certified Professional Instructor * LabVIEW Champion * Code Janitor

Have you been nice to future you?
0 Kudos
Message 8 of 23
(5,358 Views)

Hi Peter,

 

Thanks for attaching the comparison table, looks like VI Tester suits my needsSmiley Happy

 

I was mentioning NI UTF as NI tester, Sorry if I used it wrong.

 

0 Kudos
Message 9 of 23
(5,341 Views)

Hello Fab,

 

Thanks for the videos, they are really useful Smiley Happy

 

I will be waiting for more videos of yours to get the best out of testing frameworksSmiley Happy

 

 

Message 10 of 23
(5,338 Views)