Unit Testing

Getting Started & Building Your Unit Tests

The connector builder also supports unit testing, in addition to testing while developing and testing inside of a FLO. This will allow you to create a suite of tests, tied to a connector version, that can be then used to ensure that regressions have not happened between version updates and that all methods actually perform as expected.

The unit testing suite allows you to:

  • Create "unit test" methods
  • Use special assertion modules to build unit tests
  • Run individual test methods
  • Run groups of test methods
  • Run groups of tests from one version of a connector against another version

To create a unit test, select "Unit Tests" and then select "Add Test".

Once you've filled in the name of your test, and created it, you'll see two modules pop-up: "Control.Spawn" and "Assert.isEqual". These represent the basic foundations of a unit test, which are:

  • Running an action or function
  • Using an assertion to make sure the actual output of your function/action matches an expected output

Running an action or function is always handled by a control.spawn, which will run the given function. To run a given method, you must put in the "name" of your method, not the display name.

Once you've run your method with control.spawn, you now have access to the output of the method you're testing against. At this point, you will need to use assertion to determine whether or not that output is what you expect it to be.

To create an assertion, select "Add step", and choose the assertion module that best describes the way you would like to compare the output of your tested method against an expected output. This could be something as simple as Assert.IsEqual (provided on unit test creation for you), but could also be something less straight-forward like Assert.DeepProperty or Assert.Includes.

When the unit test method is run, it will compare the output of the method you're testing against each of your asserts, and display the number of successes and failures that occur inside of that unit test. It will run through every assertion before completing.

Note: Every assert module has an optional "break" flag that allows you to stop a unit test method from running if that assertion fails. This is very useful in cases in which an assertion depends on a another assertion to operate.

As you build unit tests for your connector, you'll also notice a percentage next to the "Unit Test" menu item. This represents the number of methods inside of your connector that are covered by unit tests.

Running Unit Tests

There are three different ways to run unit tests. The first allows you to run a single unit test. This is fundamentally the same as testing any method inside of the connector builder. If you simply click "Run" while inside of a unit test, it will run that test, and output logs in the log window below.

In the logs for that unit test, you'll see either red errors, or green successes and a summary below all logs that displays the total number of successes and failures. Like so:

You may also run unit tests from the Control Panel, under "Connector Unit Testing".

This will allow you to run groups of tests. This is useful when ensuring an entire connector runs to standard, or if you're trying to test multiple methods at once.

This panel allows you to select a connector version to run, and a connector version that you'll pull unit tests from. This means you can either choose to test a group of methods normally, OR to test a group of methods for regressions against a newer connector version.

To do the first type of group testing, simply choose the same connector version and testing version. It will display the available unit tests, and you can choose to run any of those tests, or all of them.

Once you do, you'll see a similar panel to when you run a normal test, but displaying all selected tests. Like so:

To run regression testing, simply choose the connector version you would like to push as the "Connector Version" and version you would like to make sure is still supported as "Testing Version". If tests fail, that means that either the original tests never passed, or that your current connector version's methods no longer output the data that the testing version expected-  meaning that FLOs built against the same version as the tests would break with your new connector version.

Unit Testing