MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

expSolution = [-1+3i, -1-3i];
testCase.verifyEqual(actSolution,expSolution)
end


The order of the tests within the block does not matter.


Save Class Definition


The following is the complete SolverTest class definition. Save this file in a folder on
your MATLAB path.


classdef SolverTest < matlab.unittest.TestCase
% SolverTest tests solutions to the quadratic equation
% ax^2 + bx + c = 0


methods (Test)
function testRealSolution(testCase)
actSolution = quadraticSolver(1,-3,2);
expSolution = [2,1];
testCase.verifyEqual(actSolution,expSolution);
end
function testImaginarySolution(testCase)
actSolution = quadraticSolver(1,2,10);
expSolution = [-1+3i, -1-3i];
testCase.verifyEqual(actSolution,expSolution);
end
end


end


Run Tests in SolverTest Test Case


Run all the tests in the SolverTest class definition file.


testCase = SolverTest;
res = run(testCase)


Running SolverTest
..
Done SolverTest




Write Simple Test Case Using Classes
Free download pdf