Tutorial: Run Connect IQ unit tests

In the previous tutorial we learned how to set up our project to be able to do unit testing, in case you didn’t read that article yet I’d advise to read it now as it’s rather essential when you also want to be able to set up unit tests for your own projects. So read the article how to create a unit test project first now. 🙂

Prerequisites for this tutorial

This tutorial is part of a tutorial series:
This tutorial continues where the last tutorial left of. If you did that tutorial you can continue with your code base or you can just download my project here instead.

Create the first unit test

First we’ll create a easy “hello world” Connect IQ unit test to get us started.
  • Create a new file StepsCarouselTests.mc under the source folder
  • In this new file we say hello world and return true to indicate succes:
The contents of the StepsCarouselTests.mc file will be:

Running unit tests

At the moment it’s unfortunately not possible to run unit tests from within the Eclipse environment, but we can run the tests from the command line. We’ll create a dos batch file to ease future test runs.

When you build your connect IQ application (Project -> Build Automatically, edit any file and save the file) you’ll see in the ConnectIQ Console something like this: Copy the part after BUILD: and place the contents in a new file called run_test.bat. Add at the end of the command. As last line we will add the pause command so that you can read errors when they occur. The contents of your batch file will look similar to: When we run this batch file we won’t see anything happening yet, but you should also see no errors. What we did so far was to build the MonkeyC application to include the unit test code.
We still miss 2 things in the batch file:
  • launch the watch simulator when it’s not yet running
  • command to run the unit tests
You can find both these items in your Connect IQ SDK directory (see Window -> Preferences -> Connect IQ -> SDK Root Directory for your location):
  • bin\connectiq -> will run the simulator
  • bin\monkeydo “.\bin\Steps Carousel Tests.prg” /t -> will actually run the tests
Be sure to add the call command in front of both these lines (in order to have the calling batch files not end the execution there).
As the Simulator takes a bit of time to start when it’s not active yet, it’s also best to put this as first action in your batch file.

The paths to the commands might be different on your system, but your final batch file will look very similar to: Remark: if you get a Symbol not found error, check that you have the –unit-test command in your build command and that the build command you copied does contain all your source files.

Test Result

When the previous edits were succesfull you will have an output in your Ms Dos window similar to: So summarized we see our debug output and that all tests have succeeded.

Source Code

You can download the full source code from here

Up next

In the next tutorial we’ll learn how to create unit tests which actually evaluate business logic.
.

Feedback

Did you like this article?Questions?
  • Post in the comments section below!

Leave a Reply