You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You want to run tests on your Arduino library (bonus: without hardware present), but the IDE doesn't support that. Arduino CI provides that ability.
8
9
@@ -12,6 +13,8 @@ You want your Arduino library to be automatically built and tested every time so
12
13
13
14
`arduino_ci` is a cross-platform build/test system, consisting of a Ruby gem and a series of C++ mocks. It enables tests to be run both locally and as part of a CI service like GitHub Actions, TravisCI, Appveyor, etc. Any OS that can run the Arduino IDE can run `arduino_ci`.
14
15
16
+
> Note: for running tests in response to [GitHub events](https://docs.github.com/en/free-pro-team@latest/developers/webhooks-and-events/github-event-types), an [Arduino CI GitHub Action](https://github.com/marketplace/actions/arduino_ci) is available for your convenience. This method of running `arduino_ci` is driven by Docker, which may also serve your local testing needs (as it does not require a ruby environment to be installed).
17
+
15
18
16
19
Platform | CI Status
17
20
---------|:---------
@@ -20,20 +23,9 @@ Linux | [](https://github.com/Arduino-CI/arduino_ci/actions?workflow=windows)
21
24
22
25
23
-
## Comparison to Other Arduino Testing Tools
24
-
25
-
| Project | CI | Builds Examples | Unittest | Arduino Mocks | Windows | OSX | Linux | License |
For a bare-bones example that you can copy from, see [SampleProjects/DoSomething](SampleProjects/DoSomething).
28
+
For a fairly minimal practical example that you can copy from, see [the `Arduino-CI/Blink` repository](https://github.com/Arduino-CI/Blink).
37
29
38
30
The complete set of C++ unit tests for the `arduino_ci` library itself are in the [SampleProjects/TestSomething](SampleProjects/TestSomething) project. The [test files](SampleProjects/TestSomething/test/) are named after the type of feature being tested.
39
31
@@ -55,13 +47,20 @@ For unit testing, you will need a compiler; [g++](https://gcc.gnu.org/) is prefe
55
47
***Windows**: you will need Cygwin, and the `mingw-gcc-g++` package. A full set of (working) install instructions can be found in `appveyor.yml`, as this is how CI runs for this project.
56
48
57
49
50
+
### You _May_ Need `python`
51
+
52
+
ESP32 and ESP8266 boards have [a dependency on `python` that they don't install themselves](https://github.com/Arduino-CI/arduino_ci/issues/235#issuecomment-739629243). If you intend to test on these platforms (which are included in the default list of platforms to test against), you will need to make `python` (and possibly `pyserial`) available in the test environment.
53
+
54
+
Alternately, you might configure `arduino_ci` to simply not test against these. Consult the reference for those details.
55
+
56
+
58
57
### Changes to Your Repo
59
58
60
59
Add a file called `Gemfile` (no extension) to your Arduino project:
61
60
62
61
```ruby
63
62
source 'https://rubygems.org'
64
-
gem 'arduino_ci'
63
+
gem 'arduino_ci''~> 1.1'
65
64
```
66
65
67
66
It would also make sense to add the following to your `.gitignore`, or copy [the `.gitignore` used by this project](.gitignore):
Copy file name to clipboardExpand all lines: REFERENCE.md
+76-10
Original file line number
Diff line number
Diff line change
@@ -39,6 +39,16 @@ This allows a file (or glob) pattern to be executed in your tests directory, cre
39
39
This allows a file (or glob) pattern to be executed in your tests directory, creating a blacklist of files to skip. E.g. `--testfile-reject=test_animal_*.cpp` would match `test_animal_cat.cpp` and `test_animal_dog.cpp` (skipping those) and test only `test_plant_rose.cpp`, `test_plant_daisy.cpp`, etc.
40
40
41
41
42
+
### `CUSTOM_INIT_SCRIPT` environment variable
43
+
44
+
If set, testing will execute (using `/bin/sh`) the script referred to by this variable -- relative to the current working directory. This enables use cases like the GitHub action to install custom library versions (i.e. a version of a library that is different than what the library manager would automatically install by name) prior to CI test runs.
45
+
46
+
47
+
### `USE_SUBDIR` environment variable
48
+
49
+
If set, testing will be conducted in this subdirectory (relative to the working directory). This is for monorepos or other layouts where the library directory and project root directory are different.
50
+
51
+
42
52
### `EXPECT_UNITTESTS` environment variable
43
53
44
54
If set, testing will fail if no unit test files are detected (or if the directory does not exist). This is to avoid communicating a passing status in cases where a commit may have accidentally moved or deleted the test files.
@@ -198,15 +208,27 @@ This test defines one `unittest` (a macro provided by `ArduinoUnitTests.h`), cal
198
208
199
209
The following assertion functions are available in unit tests.
200
210
201
-
* `assertEqual(expected, actual)`
202
-
* `assertNotEqual(expected, actual)`
203
-
* `assertLess(expected, actual)`
204
-
* `assertMore(expected, actual)`
205
-
* `assertLessOrEqual(expected, actual)`
206
-
* `assertMoreOrEqual(expected, actual)`
207
-
* `assertTrue(actual)`
208
-
* `assertFalse(actual)`
209
-
* `assertNull(actual)`
211
+
```c++
212
+
assertEqual(expected, actual); // a == b
213
+
assertNotEqual(unwanted, actual); // a != b
214
+
assertComparativeEquivalent(expected, actual); // abs(a - b) == 0 or (!(a > b) && !(a < b))
215
+
assertComparativeNotEquivalent(unwanted, actual); // abs(a - b) > 0 or ((a > b) || (a < b))
216
+
assertLess(upperBound, actual); // a < b
217
+
assertMore(lowerBound, actual); // a > b
218
+
assertLessOrEqual(upperBound, actual); // a <= b
219
+
assertMoreOrEqual(lowerBound, actual); // a >= b
220
+
assertTrue(actual);
221
+
assertFalse(actual);
222
+
assertNull(actual);
223
+
224
+
// special cases for floats
225
+
assertEqualFloat(expected, actual, epsilon); // fabs(a - b) <= epsilon
226
+
assertNotEqualFloat(unwanted, actual, epsilon); // fabs(a - b) >= epsilon
227
+
assertInfinity(actual); // isinf(a)
228
+
assertNotInfinity(actual); // !isinf(a)
229
+
assertNAN(arg); // isnan(a)
230
+
assertNotNAN(arg); // !isnan(a)
231
+
```
210
232
211
233
These functions will report the result of the test to the console, and the testing will continue if they fail.
212
234
@@ -327,7 +349,7 @@ unittest(pin_history)
327
349
// we expect 6 values in that queue (5 that we set plus one
328
350
// initial value), which we'll hard-code here for convenience.
329
351
// (we'll actually assert those 6 values in the next block)
0 commit comments