Unit Testing Protocol
For our unit tests in CV, we validate our modules using a framework called PyTest. This allows us to simply run the command ‘pytest’, and have all our tests run simultaneously (rather than have to test 1 at a time - this would be tedious).
To create a test using PyTest:
Pytest must be imported at the top of the file. It should already be present in your virtual env after having run 'pip install -r requirements.txt'
import pytest
2. Import the method/class needed for testing using absolute imports
To learn more, refer to this website
from modules.targetAquisition.targetAquisition import TargetAcquisition
3. If needed, generate test data needed to create and run the test needed
e.g
mock_camera_euler = {
'yaw': 0,
'pitch': 90,
'roll': 0
}
4. If you’re testing a class, create an instance of the class needed to test. Next, test whatever method(s) needed by passing in test data as the parameter.
e.g
5. use assert statements to finally check if the test passes or not. This can be done by knowing what the output of the test should be and asserting that the test returns that particular output
e.g
Then run it and make sure no errors occur (unless your asserting that errors occur, then it’s ok LOL)