Unit tests
The internal modules of the nRF9160: Asset Tracker v2 application have a set of unit tests in the asset_tracker_v2/tests
folder.
Following are the modules that have unit tests:
Debug module -
asset_tracker_v2/src/modules/debug_module.c
User Interface module -
asset_tracker_v2/src/modules/ui_module.c
GNSS module -
asset_tracker_v2/src/modules/gnss_module.c
JSON common library -
asset_tracker_v2/src/cloud/cloud_codec/json_common.c
LwM2M codec backend -
asset_tracker_v2/src/cloud/cloud_codec/lwm2m/lwm2m_codec.c
LwM2M integration layer -
asset_tracker_v2/src/cloud/lwm2m_integration/lwm2m_integration.c
Running the unit test
To run the unit test, you must navigate to the test directory of the respective internal module.
For example, to run the unit test for Debug module, navigate to asset_tracker_v2/tests/debug_module
.
The unit tests can be executed using West or Twister.
Running unit tests using West
Enter the following west commands to execute the tests on different board targets:
Native POSIX execution (native_posix) board target:
west build -b native_posix -t run
qemu_cortex_m3
board target:
west build -b qemu_cortex_m3 -t run
Running unit tests using Twister
Enter the following twister commands to execute the tests on different board targets:
On both Native POSIX execution (native_posix) and
qemu_cortex_m3
board targets:
twister -T .
qemu_cortex_m3
board target:
twister -T . -p qemu_cortex_m3
Running the unit tests on the nRF9160 DK
Enter the following command to execute the unit tests on nRF9160 DK:
twister -T . -p nrf9160dk_nrf9160_ns --device-testing --device-serial <serial port>
In this console snippet, serial port
must be the port where you receive logs from the DK, normally the first port listed by nrfjprog --com
, for example /dev/ttyACM0
.
The testcase.yaml
file for that unit test must have the entry platform_allow: nrf9160dk_nrf9160_ns
.
See nrf/applications/asset_tracker_v2/tests/gnss_module/testcase.yaml
for an example.
Twister can also be used to see code coverage reports. For more information about Twister, see the Test Runner (Twister) documentation.
Note
The Twister commands only work on Linux operating system.