Trouble running the unit test example

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

3 comentarios

Vivek Selvam
Vivek Selvam el 15 de Oct. de 2013
Hi Gabe
Can you attach the files? Did you try keeping both the files in the present working directory?
You can get the present working directory with the command pwd.
Gabriel
Gabriel el 15 de Oct. de 2013
I've attached the files I've been using and given a print out for pwd and dir. Thank you for replying so quickly!
per isakson
per isakson el 15 de Oct. de 2013
Which release of Matlab do you use?

Iniciar sesión para comentar.

 Respuesta aceptada

Andy Campbell
Andy Campbell el 15 de Oct. de 2013
Editada: Andy Campbell el 15 de Oct. de 2013
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

2 comentarios

Gabriel
Gabriel el 16 de Oct. de 2013
This was indeed the problem! Another member of the team had xunit in the shared directory. At least I know what to look for in future ;)
Alex
Alex el 30 de Mayo de 2016
wow, this is what happened to me as well.

Iniciar sesión para comentar.

Más respuestas (2)

Shashank Gupta
Shashank Gupta el 7 de Mayo de 2015
Editada: Shashank Gupta el 7 de Mayo de 2015
Hi All,
I am running into the same problem. My code is exactly as mentioned above by Gabriel. Basically I am trying to run the same example. And i tried everything mentioned above. Files are in the same working directory. Also, when I ran,
>> which -all runtests
'runtests' not found.
Do I not have "runtests" in my version of Matlab? I am using R2007b. Any help would be appreciated. Thank you!
James Fortier
James Fortier el 16 de Jul. de 2019

0 votos

OK, I know the thread is old, but I'm having exactly the same problem, but none of the answers above fit.
Results of which -all runtests:
>> which -all runtests
/Applications/MATLAB_R2017a.app/toolbox/risk/risk/@varbacktest/runtests.m % varbacktest method
So there is a runtests function, but it's not the correct one. Any idea why it won't find the proper one? I looked in the documentation tree to try to find which toolbox this would be in, and I can't figure it out. As you can see, I'm running 2017b.
I'm trying to run the Mathworks own script-based unit test example with the rightTri function.
Appreciate any help.
Jim

3 comentarios

Steven Lord
Steven Lord el 16 de Jul. de 2019
Can you show us the full and exact error message (all the text displayed in red) that you receive when you try running the MathWorks provided script-based unit test example as well as the exact command you wrote to try to run that example? That may provide information that will prove useful in determining what's going on.
That version of runtests you showed should be fine. It's a method of a particular type of object, and won't be called on a test. But it is odd that the runtests function for running a unit test isn't also listed. Have you had problems with your MATLAB path being corrupted in the past? Maybe the directory containing that version of runtests was removed from the path accidentally?
So it turns out my path was corrupted somehow, and I don't know why. A "restoreDefaultPath" ended up fixing the problem.
After restoring the default path, I had this, and then I was able to run the sample.
>> which -all runtests
/Applications/MATLAB_R2017a.app/toolbox/matlab/testframework/core/runtests.m
/Applications/MATLAB_R2017a.app/toolbox/risk/risk/@varbacktest/runtests.m % varbacktest method
For reference, the bad call and error message was:
>> result = runtests('rightTriTest')
Undefined function 'runtests' for input arguments of type 'char'.
>> which runtests
/Applications/MATLAB_R2017a.app/toolbox/risk/risk/@varbacktest/runtests.m % varbacktest method
It found a different runtests, that did not expect a string argument, which resulted in an error.
Steven Lord
Steven Lord el 16 de Jul. de 2019
Glad to hear it's working for you now.

Iniciar sesión para comentar.

Categorías

Productos

Preguntada:

el 15 de Oct. de 2013

Comentada:

el 16 de Jul. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by