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 .. .endfunction test1(testCase) which test1 which toBeTested % this is found...
verifyEqual(testCase, 1, toBeTested(2));endfunction 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));
Best Answer