{"id":249,"date":"2017-12-01T12:58:42","date_gmt":"2017-12-01T12:58:42","guid":{"rendered":"http:\/\/controlsoftwaresolutions.com\/?p=249"},"modified":"2019-01-21T12:47:33","modified_gmt":"2019-01-21T12:47:33","slug":"software-development-utf","status":"publish","type":"post","link":"https:\/\/controlsoftwaresolutions.com\/software-development-utf\/","title":{"rendered":"Unit Testing in LabVIEW"},"content":{"rendered":"
Adam Metcalf \u2013 Control Software Solutions<\/strong><\/p>\n As software is developed there is a need to ensure that the building blocks (units) of an application perform as expected and that bugs are not introduced. Where bugs are introduced it is necessary to detect them as early as possible. At Control Software Solutions, we achieve this by unit testing.<\/p>\n Unit testing is a process where the smallest testable parts of an application are tested to ensure that they perform as expected.<\/p>\n To successfully implement unit testing it is important that you create code that is broken down into testable units. The more modular your code, the easier it will be to test as units.<\/p>\n Consider the example shown in figure 1. Although this could be tested, since multiple calculations are performed in the same subVI it would be difficult to located any bugs:<\/p>\n Figure 1<\/em><\/p>\n This can be very quickly turned into 2 subVIs which are very easy to test, as shown by figure 2:<\/p>\n Figure 2<\/em><\/p>\n There are many obvious benefits to unit testing; for example, it allows you to find problems early and reduces the chance of bugs being introduced in your code. However, there are other benefits which might be overlooked:<\/p>\n We have created a selection of brief tutorial videos. The first provides an introduction to unit testing<\/a><\/p>\n The Unit Test Framework is a toolkit for LabVIEW that provides a way of writing, performing and automating unit tests.<\/p>\n Figure 3<\/em><\/p>\n Watch our\u00a0YouTube video:\u00a0How to Create a Simple LabVIEW Unit Test<\/a><\/p>\n Whilst there are different ways to write unit tests using the Unit Test Framework, at Control Software Solutions we prefer to use User Defined Tests. Using User Defined Tests allows us to write test cases using VIs rather than through the properties of the unit test itself. This offers several advantages:<\/p>\n The process for creating a User Defined Test is described in or YouTube video\u00a0How to Create User Defined Tests<\/a><\/p>\n At Control Software Solutions, we practice Test-Driven Development. This involves writing a test to satisfy the requirements of a VI before you write any code inside the VI. The first time you run the test, it should fail (it doesn\u2019t do anything yet!). You then write enough code inside the VI to pass the test. This means that you only write enough code to meet the requirements, which can be a significant time-saver! The process is shown by figure 4:<\/p>\n <\/p>\n Figure 4<\/em><\/p>\n Since you can re-run all the unit tests in the project any changes in your code (including when you refactor existing code) should not introduce bugs.<\/p>\n Obviously, there is some overhead to writing, running and maintaining all these unit tests, and initially it can seem slightly more time consuming, however we have found it that saves a great deal of time that may otherwise be spent chasing bugs.<\/p>\n It\u2019s no secret that creating User Defined Tests can be time consuming. This is especially true once you start adding layers of complexity, for example testing multiple test cases in parallel as shown in figure 5:<\/p>\n Figure 5<\/em><\/p>\n The problem with the process shown in figure 4 is that you will simply get a \u2018pass\u2019 or a \u2018fail\u2019. If the test fails, you will get no further information (for example, which specific test case failed?). You can use normal debugging techniques to find out, but this is time consuming and really limits the automation that we are trying to achieve by unit testing.<\/p>\n At Control Software Solutions, we have made a toolkit which eases this process, shown by figure 6: Figure 6<\/em><\/p>\n This allows very complex test cases to be very quickly built up using a selection of helper VIs.<\/p>\n The CSS Unit Test Helper also allows comprehensive reporting. If an individual component of a test fails, the whole test fails. However, the HTML report produced will quickly allow you to identify which particular component failed, as shown by figure 7:<\/p>\n Figure 7<\/em><\/p>\n Using the CSS Unit Test Helper significantly decreases the programming time required for creating user defined tests whilst increasing the information obtained from reporting.<\/p>\n For more information on any of the topics you have read in this article, or for more information on LabVIEW programming contact us<\/a>:<\/p>\nIntroduction<\/h2>\n
What is Unit Testing?<\/h2>\n
<\/p>\n
<\/p>\n
Benefits of unit testing<\/h2>\n
\n
What is the Unit Test Framework?<\/h2>\n
<\/p>\n
User Defined Tests with the LabVIEW Unit Test Framework.<\/h2>\n
\n
Test-Driven Development.<\/h2>\n
<\/p>\n
CSS Unit Test Framework Helper<\/h2>\n
<\/p>\n
<\/p>\n
<\/p>\n
Further Information<\/h2>\n