MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

testCase.choose(testCase.App.BloodPressureSwitch,'Diastolic')


% Verify ylabel changed and male Diastolic data shows
testCase.verifyEqual(ax.YLabel.String,'Diastolic')
testCase.verifyEqual(ax.Children.YData,maleDiastolicData);
end


function test_plottingOptions(testCase) ...


function test_tab(testCase) ...


end
end


Create a test_gender method that tests gender data and display. The test method
verifies the number of male scatter points and then presses the check box to include
female data. It verifies that two data sets are plotted and the color of the female data is
red. Finally, it clears the male data check box and verifies the number of plotted data sets
and scatter points. This test fails because there are 53 female scatter points instead of 50.
To take a screen shot when the test fails, use a ScreenshotDiagnostic with the
onFailure method.


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_gender(testCase)
import matlab.unittest.diagnostics.ScreenshotDiagnostic
testCase.onFailure(ScreenshotDiagnostic);


% Verify 47 male scatter points
ax = testCase.App.UIAxes;
testCase.verifyNumElements(ax.Children.XData,47);


% Enable the checkbox for female data
testCase.choose(testCase.App.FemaleCheckBox);


% Verify two data sets display and the female data is red
testCase.assertNumElements(ax.Children,2);
testCase.verifyEqual(ax.Children(1).CData,[1 0 0]);


% Disable the male data
testCase.choose(testCase.App.MaleCheckBox,false);


% Verify one data set displays and number of scatter points
testCase.verifyNumElements(ax.Children,1);
testCase.verifyNumElements(ax.Children.XData,50);
end


function test_bloodPressure(testCase)


Write Test for App
Free download pdf