MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

Write Plugin to Save Diagnostic Details


This example shows how to create a custom plugin to save diagnostic details. The plugin
listens for test failures and saves diagnostic information so you can access it after the
framework completes the tests.

Create Plugin

In a file in your working folder, create a class, myPlugin, that inherits from the
matlab.unittest.plugins.TestRunnerPlugin class. In the plugin class:


  • Define a FailedTestData property on the plugin that stores information from failed
    tests.

  • Override the default createTestMethodInstance method of TestRunnerPlugin
    to listen for assertion, fatal assertion, and verification failures, and to record relevant
    information.

  • Override the default runTestSuite method of TestRunnerPlugin to initialize the
    FailedTestData property value. If you do not initialize value of the property, each
    time you run the tests using the same test runner, failed test information is appended
    to the FailedTestData property.

  • Define a helper function, recordData, to save information about the test failure as a
    table.


The plugin saves information contained in the PluginData and
QualificationEventData objects. It also saves the type of failure and timestamp.

classdef DiagnosticRecorderPlugin < matlab.unittest.plugins.TestRunnerPlugin

properties
FailedTestData
end

methods (Access = protected)
function runTestSuite(plugin, pluginData)
plugin.FailedTestData = [];
runTestSuite@...
matlab.unittest.plugins.TestRunnerPlugin(plugin, pluginData);
end

function testCase = createTestMethodInstance(plugin, pluginData)
testCase = createTestMethodInstance@...

Write Plugin to Save Diagnostic Details
Free download pdf