matlab.unittest.TestCase Class
Namespace: matlab.unittest
Superclasses: matlab.unittest.qualifications.Assertable
, matlab.unittest.qualifications.Assumable
, matlab.unittest.qualifications.FatalAssertable
, matlab.unittest.qualifications.Verifiable
Superclass of all test classes
Description
The matlab.unittest.TestCase
class is the superclass of all test classes in
MATLAB®. It provides an interface to write and identify test content, including test
fixture setup and teardown routines.
Creating class-based tests requires subclassing the TestCase
class. To
specify tests and test fixtures, subclasses can leverage framework-specific attributes. For
more information, see TestCase Class Attributes, TestCase Method Attributes, and TestCase Property Attributes.
The matlab.unittest.TestCase
class is a handle
class.
Creation
In most cases, you are not required to create an instance of the TestCase
class directly. The test runner automatically creates TestCase
instances when
running the tests.
To create a TestCase
instance for interactive, command-line testing, use
the forInteractiveUse
static method.
Methods
Events
In addition to these events, the matlab.unittest.TestCase
class inherits
events from the Assertable
, Assumable
, FatalAssertable
, and Verifiable
classes.
Event Name | Trigger | Event Data | Event Attributes |
---|---|---|---|
ExceptionThrown | Triggered when the test runner catches an exception in the test content. An
ExceptionEventData object is passed to listener callback
functions. | matlab.unittest.qualifications.ExceptionEventData |
|
DiagnosticLogged | Triggered upon a call to the log method. A
LoggedDiagnosticEventData object is passed to listener callback
functions. | matlab.unittest.diagnostics.LoggedDiagnosticEventData |
|
Examples
More About
Tips
Defining constructor or destructor methods in a
TestCase
subclass is not recommended.TestCase
constructor and destructor methods are not considered test content and should not be used to perform qualifications. For example, theSampleTest
class specifies qualifications using a constructor method and aTest
method. However, the qualification in the constructor method does not produce a test failure. The testing framework reports only one test failure as a result of the qualification performed within thetestSize
method.classdef SampleTest < matlab.unittest.TestCase methods function testCase = SampleTest % Constructor method not recommended testCase.verifyEqual(1,2) % Does not produce a test failure end end methods (Test) function testSize(testCase) testCase.verifySize([1 2 3; 4 5 6],[2 4]) % Produces a test failure end end end