MATLAB: Trouble running the unit test example

errorMATLABrunteststestunit testing

Hullo all,
I've been considering adding Unit Tests to my code but I don't seem to be having much luck. I've followed the example on this page write-simple-test-case-with-functions but every time I try it I get an error.
I've attempted to run the tests with:
results = runtests('solverTest')
and:
results = runtests
Both attempts give me:
Error using runtests (line 100)
No test cases found.
I've checked that the files are in my path, and the the current working directory is correct. I've also tried following the source code and got as far as TestSuite.m line 232 where things seem to start going wrong for me. I'm new to Matlab so it's entirely possible that I've missed something obvious.
Appreciating any help that people can give,
- Gabe
EDIT: I've attached the files that I've been testing with. I've also checked and I am in the correct directory as follows:
>> pwd
ans =
C:\Users\galdam\Documents\MATLAB
>> dir
. dependancyMapper.m
.. quadraticSolver.m
Apps solverTest.m

Best Answer

Hi Gabe,
I think you may have a different runtests function higher on the path. Can you confirm this?
>> which -all runtests
I imagine you might have the file exchange runtests function higher on the path than the MATLAB runtests function. If so, you can remove this from the path using rmpath.
A few other ways to run the test to confirm things are in working order:
>> run(solverTest)
>>
>> tests = matlab.unittest.TestSuite.fromFile('solverTest.m');
>> run(tests)
Hope that helps!
Andy
Related Question