I have an class based test case as follows (simplified):
classdef my_test < matlab.unittest.TestCase
test_params = some_package.get_test_parameters();
function basic_test(tc, test_params)
The data returned by get_test_parameters() is used by other test cases and in other places as well.
The problem is that if I change the data returned by that function and rerun the test case the test_params are not updated because Matlab only initialize it one time when it load the my_test class into memory. Fine, but I need to make sure that when I run the test it uses the latest data from the get_test_params() function. What is the best way to do this? The running of various test cases is done in another top level function.
Some options that work but are not ideal:
- Issue "clear classes". This clears all classes and other things like global variables and persistent variables. I don't really want that. And why is "clear classes" clearing anything else but classes? What is even more stupid is that "clear ALL" does NOT clear ALL. I don't like functions that lie about what they do.
- Issue a clear my_test. But my_test is also actually inside a package and "clear" is again weird. Even if it is inside a package you should use "clear my_class", If I have multiple classes with the same name but in different packages you cannot control which class is cleared it seems. Futhermore the same syntax is used to clear a variable, so if I have a variable called my_test that will be cleared also.
In the top level file for running test cases I am creating an array of test cases with
matlab.unittest.TestSuite.fromPackage(package_of_test_cases, 'IncludingSubpackages', true)
and run them all. I want a good way to make sure that all the classes in those packages are cleared and reloaded before the test cases are run. Any ideas?