Pass a function as a property to a Test class
4 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Guru Kumaresan
on 7 Nov 2022
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 Comments
See Also
Categories
Find more on Testing Frameworks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!