matlab.unittest.TestSuite Class
Namespace: matlab.unittest
Fundamental interface for grouping tests to run
Description
The matlab.unittest.TestSuite
class is the fundamental interface used to
group tests in the testing framework. The test runner operates on arrays of
TestSuite
objects.
Creation
Create TestSuite
arrays by using static methods of the
TestSuite
class. You also can create a test suite by using the testsuite
function.
Methods
Public Methods
matlab.unittest.TestSuite.fromClass | Create test suite from test class |
matlab.unittest.TestSuite.fromFile | Create test suite from test file |
matlab.unittest.TestSuite.fromFolder | Create test suite from tests in folder |
matlab.unittest.TestSuite.fromMethod | Create test suite from single test method |
matlab.unittest.TestSuite.fromName | Create test suite from single test name |
matlab.unittest.TestSuite.fromNamespace | Create test suite from tests in namespace |
matlab.unittest.TestSuite.fromProject | Create test suite from tests in project |
matlab.unittest.TestSuite.fromRequirements (MATLAB Test) | Create test suite from requirements |
run | Run test suite using default test runner |
selectIf | Select test suite elements that satisfy conditions |
sortByFixtures | Reorder test suite based on shared fixtures |
Examples
Create Test Suites
Create different test suites and then concatenate the suites.
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
In another file named ZerosTest.m
in your current folder, create a class-based test to test the zeros
function.
classdef ZerosTest < matlab.unittest.TestCase properties (TestParameter) type = {'single','double','uint16'}; size = struct("s2d",[3 3],"s3d",[2 5 4]); end methods (Test) function testClass(testCase,size,type) testCase.verifyClass(zeros(size,type),type) end function testSize(testCase,size) testCase.verifySize(zeros(size),size) end function testDefaultClass(testCase) testCase.verifyClass(zeros,"double") end function testDefaultSize(testCase) testCase.verifySize(zeros,[1 1]) end function testDefaultValue(testCase) testCase.verifyEqual(zeros,0) end end end
Create a test suite from the function-based test file.
import matlab.unittest.TestSuite suite1 = TestSuite.fromFile("eyeTest.m");
Create a test suite from the ZerosTest
test class, including only the tests that are parameterized.
suite2 = TestSuite.fromClass(?ZerosTest,"ParameterProperty","*");
Concatenate the test suites and run the resulting suite. All the tests pass.
fullSuite = [suite1 suite2]; results = run(fullSuite);
Running eyeTest ..... Done eyeTest __________ Running ZerosTest ........ Done ZerosTest __________
Version History
Introduced in R2013aR2024a: Create test suite from namespace using fromNamespace
static method, renamed from fromPackage
The method matlab.unittest.TestSuite.fromPackage
is now named
matlab.unittest.TestSuite.fromNamespace
. The behavior of this method
remains the same, and existing instances of
matlab.unittest.TestSuite.fromPackage
in your code continue to work as
expected. There are no plans to remove support for existing references to
matlab.unittest.TestSuite.fromPackage
.
R2023a: Create test suite from tests that verify requirements
The matlab.unittest.TestSuite
class has a new static method
matlab.unittest.TestSuite.fromRequirements
that lets you create a test
suite from tests that verify requirements. You must have MATLAB®
Test™ and Requirements Toolbox™ installed to use this method.
R2019a: Create test suite from tests in a MATLAB project
The matlab.unittest.TestSuite
class has a new static method
matlab.unittest.TestSuite.fromProject
that lets you create a test suite
from the test files in a MATLAB project.
See Also
testsuite
| matlab.unittest.Test
| matlab.unittest.TestRunner
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)