MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

function testThree(testCase)
testCase.assertEqual(7*2,13,'Values not equal')
end
function testFour(testCase)
testCase.fatalAssertEqual(3+2,6);
end
end
end


The fatal assertion failure in testFour causes the framework to halt and throw an error.
In this example, there are no subsequent tests. If there was a subsequent test, the
framework would not run it.


Add Plugin to Test Runner and Run Tests


At the command prompt, create a test suite from the ExampleTest class, and create a
test runner.


import matlab.unittest.TestSuite
import matlab.unittest.TestRunner


suite = TestSuite.fromClass(?ExampleTest);
runner = TestRunner.withNoPlugins;


Create an instance of myPlugin and add it to the test runner. Run the tests.


p = DiagnosticRecorderPlugin;
runner.addPlugin(p)
result = runner.run(suite);


Error using ExampleTest/testFour (line 16)
Fatal assertion failed.


With the failed fatal assertion, the framework throws an error, and the test runner does
not return a TestResult object. However, the DiagnosticRecorderPlugin stores
information about the tests preceding and including the test with the failed assertion.


Inspect Diagnostic Information


At the command prompt, view information about the failed tests. The information is saved
in the FailedTestData property of the plugin.


T = p.FailedTestData


Write Plugin to Save Diagnostic Details
Free download pdf