This project is a template for a CI-enabled (and unit testable) Arduino project of your own.
- Travis CI
- Unit tests
- Development workflow matches CI workflow
Here is the minimal set of files that you will need to adapt to your own project:
source 'https://rubygems.org'
gem 'arduino_ci'
You'll need this to get access to the functionality.
This is different from the
Gemfile
that's included in this directory! That's for purposes of testing the ruby gem that also lives in this repository. So "do as I say, not as I do", in this case.
At a minimum, you will need the following lines in your file:
language: ruby
script:
- bundle install
- bundle exec arduino_ci.rb
This will install the necessary ruby gem, and run it. There are no command line arguments as of this writing, because all configuration is provided by...
This file controls all aspects of building and unit testing. The (relatively-complete) defaults can be found in the base project.
The most relevant sections for most projects will be as follows:
compile:
libraries: ~
platforms:
- uno
- due
- leonardo
unittest:
libraries: ~
platforms:
- uno
- due
- leonardo
This does nothing but specify a list of what platforms should run each set of tests. The platforms themselves can also be defined and/or extended in the yaml file. For example, esp8266
as shown here:
platforms:
esp8266:
board: esp8266:esp8266:huzzah
package: esp8266:esp8266
gcc:
features:
defines:
warnings:
flags:
Of course, this wouldn't work by itself -- the Arduino IDE would have to know how to install the package via the board manager. So there's a section for packages too:
packages:
esp8266:esp8266:
url: http://arduino.esp8266.com/stable/package_esp8266com_index.json
All .cpp
files in the test/
directory are assumed to contain unit tests. Each and every one will be compiled and executed on its own.
The most basic unit test file is as follows:
#include <ArduinoUnitTests.h>
#include "../do-something.h"
unittest(your_test_name)
{
assertEqual(4, doSomething());
}
unittest_main()
This test defines one unittest
(a macro provided by ArduinoUnitTests.h
), called your_test_name
, which makes some assertions on the target library. The int main
section is boilerplate.
This Arduino example was created in January 2018 by Ian Katz ianfixes@gmail.com.