Skip to content
soul4soul edited this page Apr 15, 2018 · 1 revision

Concepts

You should make a separate TestCase class for every different set of setUp and tearDown methods you'll need and make your tests members of the TestCase class whose setUp and tearDown methods they need.

In general, there are a lot of strategies and patterns for organizing tests. For example: it is very common to create one TestCase class per feature of your software under test and to create one TestCase class for every class in your software under test.

Bottom line, don't be afraid to create more than one TestCase :) In fact, you could have one TestCase for every single test, but you'll often find that you'll want to reuse your setUp and tearDown methods, which is the reason to start grouping several test methods into the same TestCase.

Designing Tests

Unit tests should be designed around the following principles:

  • Unit tests should be simple - you don't want to spend time debugging tests
  • Unit tests should only test one thing (a "unit" of code) - unit tests should help you pinpoint problems so performing multiple tests within a unit test defeats this purpose
  • Unit tests should be independent of other unit tests - they should not depend on or affect other unit tests

To facilitate these principles, unit tests should be designed to work within a test harness. A test harness is a set of VIs called 'setUp.vi' and 'tearDown.vi' that run before and after each unit test method. The test harness facilitates keeping your code simple and preventing tests from interfering with each other by providing a place to initialize and cleanup the test data. Any task that is common to the test methods you need to run should be placed in the setUp.vi method. Any task that is needed to clean up the test environment should be put in tearDown.vi.

An important aspect of the unit test framework is how data is passed from the setUp to the testMethod and tearDown.vi. The data that is passed around are actually properties of the test and so these items should be placed in the test object private data. You can edit this data by opening the {Test}.ctl file.