MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
App
end
methods (TestMethodSetup)
function launchApp(testCase)
testCase.App = PatientsDisplay;
testCase.addTeardown(@delete,testCase.App);
end
end
methods (Test)
function test_plottingOptions(testCase)
% Press the histogram radio button
testCase.press(testCase.App.HistogramButton)
% Verify xlabel updated from 'Weight' to 'Systolic'
testCase.verifyEqual(testCase.App.UIAxes.XLabel.String,'Systolic')
% Change the Bin Width to 9
testCase.choose(testCase.App.BinWidthSlider,9)
% Verify the number of bins is now 4
testCase.verifyEqual(testCase.App.UIAxes.Children.NumBins,4)
end
function test_tab(testCase) ...
end
end

Create a test_bloodPressure method that tests blood pressure data and display. The
test method verifies the y-axis label and the values of the scatter points. Then it changes
to Diastolic readings, and verifies the label and data again.
classdef TestPatientsDisplay < matlab.uitest.TestCase
properties
App
end
methods (TestMethodSetup)
function launchApp(testCase)
testCase.App = PatientsDisplay;
testCase.addTeardown(@delete,testCase.App);
end
end
methods (Test)
function test_bloodPressure(testCase)
% Extract blood pressure data from app
t = cell2table(testCase.App.Tab2.Children.Data);
t.Var2 = categorical(t.Var2);
allMales = t(t.Var2=='Male',:);
maleDiastolicData = allMales.Var7';
maleSystolicData = allMales.Var8';
% Verify ylabel and that male Systolic data shows
ax = testCase.App.UIAxes;
testCase.verifyEqual(ax.YLabel.String,'Systolic')
testCase.verifyEqual(ax.Children.YData,maleSystolicData)
% Switch to 'Diastolic' reading

33 Unit Testing

Free download pdf