Skip to content
Ken Bannister edited this page Jan 13, 2019 · 19 revisions

Unit tests are straightforward success cases. You'll find them in the tests/unittests/tests-gcoap directory in RIOT. Test cases include two scenarios:

  1. client writing a request and reading the server response
  2. server reading a request and writing a response

Unfortunately for this style of testing, much of the functionality occurs in static functions, and is difficult to test externally. That's why we have functional tests.

Also added a unit testing framework to nanocoap in sock repository PR #11.

Running the tests

$ cd tests/unittests
$ OUTPUT="COLOR" make tests-gcoap
$ make term

# Try min/max token lengths
$ OUTPUT="COLOR" CFLAGS="-DGCOAP_TOKENLEN=0" make tests-gcoap
$ make term
$ OUTPUT="COLOR" CFLAGS="-DGCOAP_TOKENLEN=8" make tests-gcoap
$ make term

Also can use OUTPUT="TEXT" above. As of this writing, use of COLOR is broken on Ubuntu 18.04.

Running on a board

$ cd tests/unittests
$ BOARD="samr21-xpro" OUTPUT="COLOR" make tests-gcoap flash
$ BOARD="samr21-xpro" make term

# Reset board to see tests run