After the framework completes evaluating the superclass method, the runTestSuite
method displays the assertion count summary.
Extend Creation of Shared Test Fixtures and TestCase Instances
Add listeners to AssertionPassed and AssertionFailed events to count the
assertions. To add these listeners, extend the methods that the test framework uses to
create the test content. The test content comprises TestCase instances for each Test
element, class-level TestCase instances for the TestClassSetup and
TestClassTeardown methods, and Fixture instances that are used when a TestCase
class has the SharedTestFixtures attribute.
Invoke the corresponding superclass method when you override the creation methods.
The creation methods return the content that the test framework creates for each of their
respective contexts. When implementing one of these methods, pass this argument out of
your own implementation, and add the listeners required by this plugin.
Add these creation methods to a methods block with protected access.
methods (Access = protected)
function fixture = createSharedTestFixture(plugin, pluginData)
fixture = createSharedTestFixture@...
matlab.unittest.plugins.TestRunnerPlugin(plugin, pluginData);
fixture.addlistener('AssertionPassed', ...
@(~,~)plugin.incrementPassingAssertionsCount);
fixture.addlistener('AssertionFailed', ...
@(~,~)plugin.incrementFailingAssertionsCount);
end
function testCase = createTestClassInstance(plugin, pluginData)
testCase = createTestClassInstance@...
matlab.unittest.plugins.TestRunnerPlugin(plugin, pluginData);
testCase.addlistener('AssertionPassed', ...
@(~,~)plugin.incrementPassingAssertionsCount);
testCase.addlistener('AssertionFailed', ...
@(~,~)plugin.incrementFailingAssertionsCount);
end
function testCase = createTestMethodInstance(plugin, pluginData)
testCase = createTestMethodInstance@...
matlab.unittest.plugins.TestRunnerPlugin(plugin, pluginData);
33 Unit Testing