Main Content

matlab.unittest.TestRunner.withNoPlugins

Class: matlab.unittest.TestRunner
Namespace: matlab.unittest

Create minimal test runner with no plugins

Description

example

runner = matlab.unittest.TestRunner.withNoPlugins creates a minimal, silent test runner with no plugins installed, and returns it as a matlab.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.

Attributes

Statictrue

To learn about attributes of methods, see Method Attributes.

Examples

expand all

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.

disp(fileread(xmlFile))
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<testsuites>
  <testsuite errors="0" failures="0" name="eyeTest" skipped="0" tests="5" time="0.25082">
    <testcase classname="eyeTest" name="doubleClassTest" time="0.015066"/>
    <testcase classname="eyeTest" name="singleClassTest" time="0.0042728"/>
    <testcase classname="eyeTest" name="uint16ClassTest" time="0.0046594"/>
    <testcase classname="eyeTest" name="sizeTest" time="0.013599"/>
    <testcase classname="eyeTest" name="valueTest" time="0.21322"/>
  </testsuite>
</testsuites>

Version History

Introduced in R2013a