Pass a function as a property to a Test class

4 visualizaciones (últimos 30 días)
Neelabh Jyoti Saharia
Neelabh Jyoti Saharia el 4 de Nov. de 2022
Respondida: Guru Kumaresan el 7 de Nov. de 2022
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?

Respuestas (1)

Guru Kumaresan
Guru Kumaresan el 7 de Nov. de 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!

Categorías

Más información sobre Testing Frameworks en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by