Unit test can't see the function it needs to test
显示 更早的评论
This is my first time creating unittest, and I am having trouble directing unitTestClass to see the function it tests, which lives in a different directory.
I have the following directory structure:
+utilityFUnctions/
utilityFunction1.m
utilityFunction2.m
+computeFunctions/
computeFunction1.m
computeFunction2.m
unit_tests
unitTestClass.m
test_data/
unitTestInputData.mat
unitTestExpectedOut.mat
mainFunction.m
runAllUnitTests.m
Here is the content of the runAllUnitTest.m:
This basically will run all tests in unit_tests folder
import matlab.unittest.TestSuite
suiteFolder = TestSuite.fromFolder('unit_tests');
result = run(suiteFolder);
And this is the content of unit_tests/unitTestClass.m:
classdef computeFunction1Test < matlab.unittest.TestCase
methods (Test)
function testCase1(testCase)
[input1, input2] = load('test_data/unitTestInputData.mat')
act = compute.computeFunction1(input1, input2);
exp = load('test_data/unitTestExpectedOut.mat')
testCase.verifyEqual(act, exp)
end
end
end
When I run runAllUnitTest.m I get the following error:
Undefined function 'compute.computeFunction1'
I suspect that at the time of execution, working directory is /unit_tests and therefore not recognizing compute directory and functions in the directory.
Is there a way to keep the current directory structure and make the unit test work?
3 个评论
per isakson
2020-11-13
Is the parent folder of +computeFunctions/ on the Matlab search path?
Louis
2020-11-13
Louis
2020-11-13
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Search Path 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!