Unit tests - SFH-code/VigiSense GitHub Wiki
Symptom Check Unit Tests
Unit tests were set up for the determination of symptoms based on the biosignal values. There are two unit test modules, one for the heart rate and one for the blood oxygen levels.
The aim of these unit tests is to confirm the validity of the added feature that is able to read and compare the detected biosignal values and compare those with a predefined symptom list.
Unit tests were developed on the Unit-Tests branch and can be found on the main branch as well.
Steps taken to set the unit tests
To add a new unit test, you would need to figure out what function to test and which file the function resides in. This backhanded way uses derived and related classes to test is because classes rely on sensor values that come in intervals based on the interrupts. This means that functions are encapsulated in a process that separates the conversion of raw infrared and red intensity values to oxygen level and heart rate values.
An example implementation:
Assuming you want to test the functionality of alerting another user using fastdds. Looking at the source code, this function resides in any implementation of the virtual class DiagnosisInterface.h as the function ping(). ping relies on getSPO2 or getHR which is a function of both the SPO2Tracker class. To add a unit test:
-
Make a header file specifically for unit test in this case:
testParent.h, -
Make a new class called
sensorTestas a related class tosensorto override certain values. Make thetestParent.hclass defined as a virtual parent class ofsensorTestandsensorclass. Include the functions that are to be tested.
- Define functions to control values that come in through raw sensor values.
- In the unit test implementation file (
unitTest.cpp) define test cases using functions in [2]. Where the pointer pass into theSPO2Trackerconstructor is an instance ofsensorTestinstead ofsensor.
Check out the source code for how diagnosisInterface derived classes (such as SPO2 Tracker) are called for a better understanding of code architecture. It uses threads to call functions such as getSPO2() that are defined in either sensor or sensorTest.