Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

runtests option to run a single test from file

Is there a way to run a single test in a matlab.unittest.TestCase class? I have a file with about 15 tests but I only want to run one of them. I normally run the whole file with

runtests('test/disaggregationtests.m')

I was expecting to be able to do something like

runtests('test/disaggregationtests.m', 'Name', 'testWeekDisaggGrowth')

but this results in an empty TestResult.

like image 244
David Kelley Avatar asked Dec 15 '25 18:12

David Kelley


1 Answers

Some of this depends on the version of MATLAB you are using, but there are a variety of ways to run a single test, as well as multiple ways to determine what a single test is, since with test parameterization ([1], [2], [3]) a single test method can actually produce multiple tests that can each independently run. Note the "Name" of each test matches the name property of the Test array returned by testsuite or TestSuite.fromFile, etc. It is also what shows when a failure happens.

Here are a couple things you can do in the most recent version of MATLAB (R2019a). Earlier versions may have differing support.

1) Run through directly using the name as the first argument (test must be available on the path, hence the cd)

>> cd test
>> runtests disaggregationtests/testWeekDisaggGrowth 

2) Use the Name of the test as a name/value pair. EDIT: you can simply point to the folder as the first arg

>> runtests('test', 'Name', 'disaggregationtests/testWeekDisaggGrowth')

3) Use the run tests toolstrip button to run the test where your current cursor is in the editor. Note this will run all parameterizations of chosen test so it may or may not be what you want.

Run Current Test

4) Use the TestProcedure name value pair. Note this will run all parameterizations of chosen test so it may or may not be what you want

>> runtests('test/disaggregationtests.m', 'TestProcedure', 'testWeekDisaggGrowth')

Hope that helps!

like image 95
Andy Campbell Avatar answered Dec 18 '25 03:12

Andy Campbell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!