matlab.unittest.TestRunner.withNoPlugins - Create minimal test runner with no plugins - MATLAB (original) (raw)
Main Content
Class: matlab.unittest.TestRunner
Namespace: matlab.unittest
Create minimal test runner with no plugins
Syntax
Description
runner = matlab.unittest.TestRunner.withNoPlugins
creates a minimal, silent test runner with no plugins installed, and returns it as amatlab.unittest.TestRunner
object. The returned test runner is the simplest runner possible and produces no text output.
Use this method to create a test runner when you want to have complete control over which plugins are added to the runner.
Examples
Generate JUnit-style test results by creating a minimal runner and then adding an XMLPlugin
instance to the runner.
In a file named eyeTest.m
in your current folder, create a function-based test to test the eye
function.
function tests = eyeTest tests = functiontests(localfunctions); end
function doubleClassTest(testCase) actual = eye; verifyClass(testCase,actual,"double") end
function singleClassTest(testCase) actual = eye("single"); verifyClass(testCase,actual,"single") end
function uint16ClassTest(testCase) actual = eye("uint16"); verifyClass(testCase,actual,"uint16") end
function sizeTest(testCase) expected = [7 13]; actual = eye(expected); verifySize(testCase,actual,expected) end
function valueTest(testCase) actual = eye(42); verifyEqual(testCase,unique(diag(actual)),1) % Diagonal values must be 1 verifyEqual(testCase,unique(triu(actual,1)),0) % Upper triangular values must be 0 verifyEqual(testCase,unique(tril(actual,-1)),0) % Lower triangular values must be 0 end
To run the tests, first import the classes used in this example.
import matlab.unittest.TestRunner import matlab.unittest.plugins.XMLPlugin
Create a test suite from the tests in eyeTest.m
.
suite = testsuite("eyeTest.m");
Create a test runner with no plugins. This code creates a silent runner that produces no output.
runner = matlab.unittest.TestRunner.withNoPlugins;
You can now add any plugins you choose. Create a plugin that writes JUnit-style XML output to the file myTestResults.xml
in your current folder. Then, add the plugin to the test runner.
xmlFile = "myTestResults.xml"; p = XMLPlugin.producingJUnitFormat(xmlFile); addPlugin(runner,p)
Run the tests. In this example, all the tests pass.
results = run(runner,suite);
View the contents of the generated artifact.
Version History
Introduced in R2013a