In a file in your working directory, create a new output
stream class in the file ToFigure.m
. This class
allows plugin output to be redirected to a figure.
This class uses two properties. Figure
is
the figure that receives and displays the output. ListBox
is
a handle to the list box that displays the text.
In the same file, add the following methods
block.
You must implement the print
method for any
subclass of OutputStream
. In this example, the
method creates a new figure (if necessary), formats the incoming text,
and then adds it to the output stream.
In the same file, add the following methods
block
containing a helper function to create the figure.
In an new file in your working folder, create ExampleTest.m
containing
the following test class.
The verifyEqual
qualification in testOne
causes
a test failure. The qualifications in testOne
and testTwo
include
an instance of a matlab.unittest.diagnostics.StringDiagnostic
.
At the command prompt, create a test suite from the ExampleTest
class.
Create a test runner that displays output to the command
window.
Create a DiagnosticsValidationPlugin
that
explicitly specifies that its output should go to a figure via the ToFigure
output
stream.
Add the plugin to the TestRunner
and
run the suite.
Running ExampleTest
================================================================================
Verification failed in ExampleTest/testOne.
----------------
Test Diagnostic:
----------------
Testing 5==4
---------------------
Framework Diagnostic:
---------------------
verifyEqual failed.
--> The values are not equal using "isequaln".
--> Failure table:
Actual Expected Error RelativeError
______ ________ _____ _____________
5 4 1 0.25
Actual double:
5
Expected double:
4
------------------
Stack Information:
------------------
In C:\work\ExampleTest.m (ExampleTest.testOne) at 4
================================================================================
...
Done ExampleTest
__________
Failure Summary:
Name Failed Incomplete Reason(s)
==================================================================
ExampleTest/testOne X Failed by verification.
Only the test failures produce output to the screen. By default, TestRunner.withTextOutput
uses
a FailureDiagnosticsPlugin
to display output on
the screen.
In addition to the default text output being displayed
on the screen, the DiagnosticsValidationPlugin
output
is directed to a docked figure. The figure shows the following text.
------------------------------
Validation of Test Diagnostic:
------------------------------
Testing 5==4
------------------------------
Validation of Test Diagnostic:
------------------------------
Testing 5==5
The DiagnosticsValidationPlugin
displays
the diagnostic information regardless of whether the tests encounter
failure conditions.