How can I make my test find a second function in a neighboring file?
Show older comments
I inherited some matlab files and I want to write tests for them.
Each file contains multiple function declarations.
It seems like I can only access the top-level function. How do I make tests for the other functions?
(I did the OnRamp course...)
File: toBeTested.m
function value = toBeTested(x)
value = toBeTested2(x) - 1;
end
function value = toBeTested2(x)
value = x;
end
File: toBeTestedTest.m
function tests = toBeTestedTest
tests = functiontests(localfunctions);
end
function setupOnce(~)
addpath .. .
end
function test1(testCase)
which test1
which toBeTested % this is found...
verifyEqual(testCase, 1, toBeTested(2));
end
function test2(testCase)
which test2
which toBeTested2 % this says it can't be found :?(
verifyEqual(testCase, 2, toBeTested2(2)); % This fails, with an error
end
When I open the file in the LiveEditor, it prompts me with a RunTests button.
The test1 passes. test2 fails with:
Error occurred in toBeTestedTest/test2 and it did not run to completion.
---------
Error ID:
---------
'MATLAB:UndefinedFunction'
--------------
Error Details:
--------------
Undefined function 'toBeTested2' for input arguments of type 'double'.
Error in toBeTestedTest>test2 (line 18)
verifyEqual(testCase, 2, toBeTested2(2));
Accepted Answer
More Answers (0)
Categories
Find more on Whos in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!