Adding Unit Tests

Unit tests can be used to evaluate program functions and / or classes directly.

Here is a brief list of some of the unit testing frameworks that are installed on their respective stack environment:

  • C# - nunit

  • Java - JUnit

  • Python - unittest

  • C++ - gtest

  • JavaScript (node.js) - mocha/chai/sinon

  • Swift - XCTest

A unit test's options are described in detail below.

Unit Test Design Template

The unit test design template

Common Options

Options that are used for both basic and advanced unit tests are shown below.

Description

A summary of what this unit test is checking. Shown to users if test is shared.

Advanced

Toggle the advanced unit test form.

Advanced unit test template

The advanced unit test template allows you to write unit tests the traditional way. Each advanced unit test template comes with an example of the testing module for that test framework in that environment.

Imports

A list of files to import into the unit test (e.g. header files, source files). Add one per line.

Basic Options

Class Name

The optional name of the class to instantiate an instance of to test.

Class Parameters

The optional parameters to use when initializing the class instance.

Function

The function / method to call. If a class name is provided, this will be called against the instantiated class instance.

Parameters

The parameters to pass to the function / method.

Operator

The comparison operator to use.

Value

The value the function / method should return.

Advanced Options

Test Contents

The full test contents (excluding imports) to run.

Command

Optionally specify a command to run the unit test.

Completed unit test

This unit test is testing to determine that a method, .add(), correctly adds the value of x to a set. Another unit test might test the result of adding -x to the set, where the set should handle -x and x in two different ways.

  1. Test Output - Test output is the result of the unit test. Unit tests are small snippets of code on their own so there may be additional information that is generated to the benefit of the reader. This is also an area where users may become confused as unit test output can be complicated and verbose, containing lots of low level information a user is not familiar seeing. it is important to create unit tests with this possibility in mind.

  2. Test Contents - contains the contents of the unit test or unit tests, as there can be multiple. This is the code that is being run against the user's code. In certain circumstances the unit test will be above the user's skill level in that language. The content of a unit test is not designed to be user-friendly, it is designed to test the code.