MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

TestFigure
end


methods(TestMethodSetup)
function createFigure(testCase)
% comment
testCase.TestFigure = figure;
end
end


methods(TestMethodTeardown)
function closeFigure(testCase)
close(testCase.TestFigure)
end
end


methods(Test)


function defaultCurrentPoint(testCase)


cp = testCase.TestFigure.CurrentPoint;
testCase.verifyEqual(cp, [0 0], ...
'Default current point is incorrect')
end


function defaultCurrentObject(testCase)
import matlab.unittest.constraints.IsEmpty


co = testCase.TestFigure.CurrentObject;
testCase.verifyThat(co, IsEmpty, ...
'Default current object should be empty')
end


end


end


Test Case with Class-Level Setup Code


The following test case, BankAccountTest, contains setup code at the class level.


To setup the BankAccountTest, which tests the BankAccount class example described
in “Developing Classes — Typical Workflow”, add a TestClassSetup method,
addBankAccountClassToPath. This method adds the path to the BankAccount


Write Setup and Teardown Code Using Classes
Free download pdf