Create a test suite from two test files, run the suite, and
generate a .html
report of the results.
Create a new file in your working folder named
ScriptBasedTest.m
containing the following test
script. The script includes two failing and incomplete tests.
Create a file named ClassBasedTest.m
containing the
following test class. The class includes a failing test that, with
parameterization, results in nine failed tests.
classdef ClassBasedTest < matlab.unittest.TestCase
properties (ClassSetupParameter)
generator = {'twister','combRecursive','multFibonacci'};
end
properties (MethodSetupParameter)
seed = {0,123,4294967295};
end
properties (TestParameter)
dim1 = struct('small',1,'medium',2,'large',3);
dim2 = struct('small',2,'medium',3,'large',4);
dim3 = struct('small',3,'medium',4,'large',5);
type = {'single','double'};
end
methods (TestClassSetup)
function ClassSetup(testCase,generator)
orig = rng;
testCase.addTeardown(@rng,orig)
rng(0, generator)
end
end
methods (TestMethodSetup)
function MethodSetup(testCase,seed)
orig = rng;
testCase.addTeardown(@rng,orig)
rng(seed)
end
end
methods (Test, ParameterCombination='sequential')
function testSize(testCase,dim1,dim2,dim3)
testCase.verifySize(rand(dim1,dim2,dim3),[dim1 dim2 dim3])
end
end
methods (Test, ParameterCombination='pairwise')
function testRepeatable(testCase,dim1,dim2,dim3)
state = rng;
firstRun = rand(dim1,dim2,dim3);
rng(state)
secondRun = rand(dim1,dim2,dim3);
testCase.verifyEqual(firstRun,secondRun);
end
end
methods (Test)
function testClass(testCase,dim1,dim2,type)
testCase.verifyClass(rand(dim1,dim2,type),type)
end
end
end
At the command prompt, create a test suite from both test files.
suite =
1×284 Test array with properties:
Name
ProcedureName
TestClass
BaseFolder
Parameterization
SharedTestFixtures
Tags
Tests Include:
17 Unique Parameterizations, 0 Shared Test Fixture Classes, 0 Tags.
Create a silent test runner, so that there is no information output to the
Command Window. Create a TestReportPlugin
that generates a
.html
test report in a folder named
myResults
.
Add the plugin to the TestRunner
and run the suite.
Generating report. Please wait.
Preparing content for the report.
Adding content to the report.
Writing report to file.
Report has been saved to: C:\work\myResults\index.html
result =
1×284 TestResult array with properties:
Name
Passed
Failed
Incomplete
Duration
Details
Totals:
282 Passed, 2 Failed, 2 Incomplete.
1.6712 seconds testing time.
Open the test report by clicking the name of the saved file. In this
example the file name is
C:\work\myResults\index.html
.