Hello everyone,
Please see below an example of a unit test.
What is the relevance of “entities={1: MockedEntity(entity_type=“my_mocked_entity”)}”?
What can I do with it that can’t be done without this line?
# 1 - Imports from app
# 1.1 - Import the class Controller to be tested
# 1.2 - Import the function to be tested (if outside Controller)
# 2. Imports from libraries/viktor
import unittest
from viktor.testing import (
MockedEntity,
mock_params,
mock_View,
)
class TestController(unittest.TestCase):
def test_myfunc(self):
# A nested dict with steps and parameters
params_args = {
"my_step": {
"param_1": 1,
"param_2": 'some value',
}
}
# Mock the parametrization
mocked_params = mock_params(
params=params_args, # the nested dict
parametrization=Controller.parametrization(), # a parametrization instance, don't forget ()
entities={1: MockedEntity(entity_type="my_mocked_entity")} # if not relevant, delete this line
)
# Here get result returns a numerical value, as an example case
result = get_result(params=mocked_params)
self.assertEqual(result, 1.0)