Caraya Review

Caraya Review

Caraya is a popular Unit Testing solution from JKI. Compared to JKI VI Tester, Caraya seems to be newer and better supported. In fact while conducting this review I found a small bug. I reported it and it was fixed within 24 hours.

The Caraya paradigm is different from the xUnit paradigm. It is based off of Assertions. The easiest way to understand it is to look through the examples.

Installing Caraya

Caray installs using VIPM

Examples

Caraya comes with a bunch of examples. They are in the <LabVIEW>\Examples\JKI\Caraya folder. There is a readme which explains each of the examples.

If you look in the LabVIEW Examples directory, you will find some Caraya examples. There is a readme that explains what each example demonstrates.

Assertions

The first part to understanding Caraya is understanding assertions. Assertions come from text based programming. Many text based languages include assertions. Assertions are meant to be a part of your running production code. They are meant to catch errors in programming logic that put the system into an invalid state. This is different than typcial errors caused by the user doing something they shouldn’t or hardware malfunctioning. As an example if you were writing software for a traffic light, you might have an assertion that at least 1 direction (E-W,N-S) must have a red light at any given time.

In adddtion to acting as a unit testing tool, Caraya can be used as an assertion tool to detect invalid states of the software at runtime. in that way it is unique from the other unit testing solutions.

This VI asserts that the Pump Speed must be between 0 and 5 inclusive. If that is not true it will generate an error.
Running the above VI generates this error.

Simple Tests

In Caraya unit tests are built upon assertions. You call the vi you want to test with known inputs and make an assertion based on the output. First though, you must call Define Test.vi This will cause the Caray GUI to display when you run the test. You can name your test here or leave that input blank and Caraya will pick up the name of the vi. My advice would be to leave that input blank then when you get the Caraya Test Results it’s easy to find the code for a particular test. After you call Define Test.vi you need to call at least 1 assert vi. Behind the scenes each assert VI communicates with the GUI to report Results.

An example of a simple Caraya Unit Test. The add function would get replaced by the VI you want to test.

Running Tests

To run a test simply run the test VI. The Caraya GUI will automatically launch and display the results.

Here are the results for a test that passes.
Here are the results for a test that fails.

Nesting Tests

Tests can easily be nested in Caraya, simply by running them in parallel and throwing a Define Test.vi in front of them.

Tests in Caraya can easily be grouped by running them in parallel and putting a Define Test.vi out in front.
Here are the results from a grouped test.

Programmatic Testing

To run Caraya Test automatically, you must drop a Define Test Suite VI before the tests and a Destroy Test Suite VI afterwards. The Define Test Suite VI is polymorphic and lets you choose what type of report you want to produce. It also allows you to specify whether you want the GUI to display or not.

Here is the test suite example for running tests programmatically.
The define test suite is used to tell Caraya to hide the GUI and output a report.
Here are the different report formats.