MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
To explore the properties of this app prior to testing, create an instance of the app at the
command prompt.

app = ConfigurePlotAppExample;

This step is not necessary for the tests, but it is helpful to explore the properties used by
the app tests. For example, use app.UpdatePlotButton to access the Update Plot
button within the app object.

Create a test class that inherits from matlab.uitest.TestCase.

classdef testConfigurePlotAppExample < matlab.uitest.TestCase

methods (Test)

end

end

Create a test method test_SampleSize to test the sample size. The test method
modifies the sample size, updates the plot, and verifies that the surface uses the specified
sample size. The call to addTeardown deletes the app after the test is complete.

classdef testConfigurePlotAppExample < matlab.uitest.TestCase

methods (Test)
function test_SampleSize(testCase)
app = ConfigurePlotAppExample;
testCase.addTeardown(@delete,app);

testCase.type(app.SampleSizeEditField,12);
testCase.press(app.UpdatePlotButton);

ax = app.UIAxes;
surfaceObj = ax.Children;
testCase.verifySize(surfaceObj.ZData,[12 12]);
end
end

end

Create a second test method test_Colormap to test the colormap. The test method
selects a colormap, updates the plot, and verifies that the plot uses the specified
colormap. The full code is now as follows.

33 Unit Testing

Free download pdf