How can I set a unit test class variable from a test function?
이전 댓글 표시
I am trying to write a unit test class that includes a teardown function that writes a simple report. During execution of the different tests, I'd like to set some class variables that can then be accessed by the teardown function. I've created a simple example below to illustrate this. In this example, why is it that the test01 function can set testCase.variable, but the teardown function doesn't see it?
classdef testClass < matlab.unittest.TestCase
properties
variable = []
end
methods (TestClassTeardown)
function teardown(testCase)
fprintf('Variable was set to %i', testCase.variable);
end
end
methods(Test)
function test01(testCase)
testCase.variable = 5;
testCase.verifyEqual(testCase.variable, 5);
end
end
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Write Unit Tests에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!