Change SimulationMode programmatically for one test run in TestSuite/TestRunner

3 views (last 30 days)
Hello,
i run multiple tests with the following commands:
import matlab.unittest.TestSuite
import matlab.unittest.TestRunner
mytestsuite = testsuite('mytestmanager.mldatx') %this holds multiple external harness files
mytestrunner = TestRunner.withNoPlugins;
results = table(run(mytestrunner, mytestsuite));
For the test run, i would like to change the SimulationMode (see https://www.mathworks.com/help/simulink/ug/choosing-a-simulation-mode.html ) to Accelerator Mode.
This could normally be changed in the harness file. But how can i do this programmatically for my test run? From my understanding only the testrunner creates the TestClass where i maybe could change that parameter..
Thanks!
( I use Matlab 2019b )

Answers (1)

Pratik Patil
Pratik Patil on 20 Nov 2020
Hello Alexander,
I assume you are trying to modify the simulation mode of the testcase in Simulink test file.
You can achieve the same using following lines of code in your script:
tf = sltest.testmanager.TestFile('mytestmanager');
ts = tf.getTestSuites % get first level of test suite in test file
tc = ts.getTestCases % get first level of test case in test suite
setProperty(tc, 'SimulationMode', 'Accelerator'); % set simulation mode to 'Accelerator'
You can refer to documentation for other 'setProperty' options:
https://www.mathworks.com/help/sltest/ref/sltest.testmanager.testcase.setproperty.html

Categories

Find more on Results, Reporting, and Test File Management in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!