Viewpoint Systems, Inc.
800 West Metro Park
Rochester, NY 14623
Phone: 585.475.9555
Fax: 585.475.9645
Viewpoint Data Management, LLC.
800 West Metro Park
Rochester, NY 14623
Phone: 585.475.9555
Fax: 585.475.9645
Viewpoint News, February 2009
In our last article we explored using TestStand as our test execution framework for doing test driven development (TDD) in LabVIEW. This method however has one major drawback; you need to acquire a copy of TestStand and install it on every machine you are doing development on.
For large corporations who may already have ample licenses to TestStand this may not be an issue, however for the rest of us TestStand can impose an additional development cost to any project.
In this article I will explore JKI’s VI Tester for LabVIEW, a free, standards driven unit testing framework.
JKI’s VI Tester can be found as part
of the VI Package Manager (http://jkisoft.com/vipm/ ). VI Tester’s homepage (http://forums.jkisoft.com/
Do take note on the requirements page
(http://forums.jkisoft.com/
For the remainder of this article I am going to assume you have successfully downloaded and installed VI Tester before continuing, and if you haven’t go ahead and set it up, don’t worry, I’ll wait.
All setup and running? Great, let’s take a look at how we can use VI Tester to do TDD in LabVIEW. For an apples to apples comparison to my TestStand article I am going to use the same problem:
Design a VI that will tell us given three integers if they form a right triangle.
Since we have already done this project using TestStand I am going to leave out all of the theory and choosing the first test steps that I did in part 2. Let’s get right down to business and take the VI we left off with in the last article shown in Figure 1. and Figure 2.
Figure 1 Front Panel Right Triangle Checker
Figure 2 Block Diagram Right Triangle Checker
I’ve taken my ‘Right Triangle Checker’ and added it to a new project called aptly ‘Triangle Checker’. Time to start adding some tests! In the project explorer I am going to select ‘Tools/VI Tester/New/Test Case…’. This will bring up a file save dialog box asking me where I want to save my new test case and what I want to call it. For this project I’m going to call my test case ‘Tests’ and save the test case in the same directory as the code I am currently developing. The resulting project explorer can be seen in Figure 3.
Figure 3 Test Case Added to Project Explorer
VI Tester has added a new class to our project where we are going to place all of our test code. Notice the three Vis VI Tester created:
setUp.vi – All code that needs to be run before each test VI executes should reside here
tearDown.vi – All code used to clean up after each test VI is placed here
testExample.vi – A template VI that provides a starting point in creating tests
We are not going to dive into the set
up and tear down VIs this article, refer to the support forms for further
information on how you can use them in your testing, (http://forums.jkisoft.com/
To create our first test we are going to take a look at the testExample.vi as seen in Figures 4 and 5.
Figure 4 Front Panel
Test VI
Figure 5 Block Diagram Test VI
Figure 5 has a new VI that is provided
by VI Tester that will test if two items provided to it are equal.
For a complete rundown of all of the VIs provided by VI Tester check
out the videos on VI Tester’s website towards the bottom of the page
(http://forums.jkisoft.com/
Our first test is going to be:
To do this we need to create new test
VIs for the test case. The easiest method is to create a copy
of the current template VI and add our VI we want to test. This
is described in detail on VI Tester’s website at the top of the page
(http://forums.jkisoft.com/
The short version:
Now that we have a new test VI we are going to modify it to test our ‘Right Triangle Checker’ for negative input.
We just created our first test case using VI Tester!
If you followed all of the steps I
outlined above you should have a block diagram like Figure 6.
Figure 6 Check for Negative Input Test VI
VI Tester excels over a similar TestStand implementation in several aspects:
Where VI Tester really takes off is when we start actually running the test, let’s run our first test now.
Navigate back to the project explorer. Select from the menu bar ‘Tools/VI Tester/Test VIs…’, this will bring up the test runner as shown in Figure 7.
Figure 7 VI Tester Test Runner
A full run down of the features/description
of the functions can be found at http://forums.jkisoft.com/
For our purposes we are going to focus on the green ‘Play’ button at the top of the runner, this will kick off running all of the tests.
After the run we have immediate feedback on the status of each test as seen in Figure 8.
Figure 8 Results of Running our Tests
We can see that we ran two tests (one real test, the other example test we haven’t removed yet). Let’s add three more tests:
I am leaving the process of creating each one of those tests up to the reader. However if you are following along with the same block diagram as I have for my ‘Right Triangle Checker.vi’ by the time you implement and run the last test you are going to have Figure 9.
Figure 9 Test Failure
If you take a look back at Figure 2 the block diagram for our VI under test you’ll see that if we provide the sides in the order of 5, 4, 3 our VI will fail even though 5, 4, 3 are valid sides of a right triangle. We can quickly see from Figure 9 which one of our tests has failed and a big red bar at the top of the screen to bring to our attention one or more of our tests have failed.
Once we refactor our VI under test, we can quickly re-run all of our tests to validate that any changes to the VI don’t cause errors in any of our other tests. This is the key to TDD: having a full set of regression tests that we can run quickly and ensure any changes we make to our code at any time can be fully tested against a suite of tests and validate that every change we make to the code still produces functioning code.