Pass a function as a property to a Test class
4 次查看(过去 30 天)
显示 更早的评论
Hi, I am new to the unit test framework. I am writing a simple test class with two test methods as shown below.
classdef Tester_Class < matlab.unittest.TestCase
properties
num
expSolution1
expSolution2
end
methods(Test)
function squareTest(testCase, num, expSolution1)
[actSolution, ~] = exampleFunction(num);
testCase.verifyEqual(actSolution,expSolution1)
end
function rootTest(testCase, num, expSolution2)
[~, actSolution] = exampleFunction(num);
testCase.verifyEqual(actSolution,expSolution2)
end
end
end
I want the two test methods to be able to test the function exampleFunction that gives two output (square of the number and root of the number). I want to pass the number on which the function under test will work on, and the two expected output, like
Tester = Tester_Class('num', 9, 'expSolution1', 81, 'expSolution2', 3)
How can I do this?
0 个评论
回答(1 个)
Guru Kumaresan
2022-11-7
Hi Neelabh,
From my understanding, you are trying to pass external parameters that are not defined in the test file itself. This can be done by creating an array of Parameter instances, and then use the ExternalParameters name-value argument with TestSuite creation methods such as fromClass.
You can also refer to MathWorks Documentation page for Using External Parameters in Parameterized functions.
Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Testing Frameworks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!