Pass a function as a property to a Test class
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Guru Kumaresan
il 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 Commenti
Vedere anche
Categorie
Scopri di più su Testing Frameworks in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!