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:

ย 

  1. 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)