TDD Comes to Arduino

When I first started looking into unit testing and test driven development for embedded, way back when, I was confronted with tools and techniques that were totally new to me. I was eventually successful in setting up an environment, but now I want to share an example so simple, and a list of instructions so complete, that pretty much anyone can start to do TDD in embedded. I also want to demonstrate how simply this can be accomplished without the need for a cumbersome GUI. Right now, there’s no more ubiquitous embedded development kit than the Arduino family of hardware, so that’s what we’re going to use. Oh, and there’s an awesome open source tool chain for it, more on that later. The example project is basically a fully tested, and Ceedling-ified Arduino_C_Scaffold. So, major credit is due to that project for providing a great foundation. This write up is going to go over absolutely everything needed to bring up a bone stock Windows XP development environment. If you’re using Mac OS or Linux see the Arduino_C_Scaffold project for non-Ceedling related details.

Getting Started

  1. Install ruby – The language that Ceedling is built on.
    a. Download the Ruby installer from http://rubyinstaller.org/
  2. b. Install and select “Add Ruby executables to your PATH”
    c. Press Start, select Run and type in “cmd”. At this point you should be able to run “ruby -v” here at the command prompt. You should see something like “ruby 1.9.3…”

  3. Install Ceedling – This is the testing framework that’s going to take care of creating mock functions, executable test programs, and showing you the results, among other things.
    a. Type “gem install ceedling”
    Now you should be able to just type “ceedling” and see the a list of available commands that Ceedling will accept.

  4. Install MinGW – This will give your windows machine the ability to compile and run programs similarly to how you would on Linux. It provides a ported version of gcc which is the compiler that Ceedling will use to build and run your tests locally on your computer.
    a. Download http://sourceforge.net/projects/mingw/files/MinGW/
    b. Install using all defaults

  5. Install WinAVR
    a. Download 20100110 at http://sourceforge.net/projects/winavr/files/WinAVR/20100110/
    b. Install using all defaults

  6. Install Arduino Drivers
    a. The easiest way to do this is to download and install the Arduino software. If you’re already developing with an Arduino then you’re done with this step.
    b. Otherwise download and install this: http://arduino.cc/en/Main/Software
    c. Then, install the drivers as described here http://arduino.cc/en/Guide/Windows#toc4

  7. At the command prompt run “ceedling example blinky”
  8. Configure your project
    a. We’re almost done. Go into Device Manager and see what COM port your Arduino is connected too.
    b. Open up the Blinky folder and double-click on the poject.yml file.
    c. On the line that says “- serial_port” change the number, to the port number your are using.
    d. If you’re using windows you will have to uncomment a few lines. Remove the # character from the lines starting with “- :path:” down to “- #{ENV[‘PATH’]}”
    d. Save the file.

  9. Finally, try it out.
    a. Move your current directory to the “blinky” project. Enter “cd blinky”.
    b. All tasks will begin with “rake”. Type “rake -T” to see a list of available tasks.
    c. Type “rake test:all” and press enter. Ceedling will then test all the tests in your project.
    d. To flash your Arduino and see it run just type “rake program” and press enter.
    e. Go ahead and browse the src and test folders. You’ll get a good picture for how to write unit tests. For more information on Ceedling visit here.
Conversation
  • […] C and prefer test-driven development, I followed Nick Christensen’s detailed instructions on how to set up an Arduino development environment with gcc, Unity, and CMock. The gcc compiler is an industry standard tool these days, and I like Unity and CMock for unit […]

  • Comments are closed.