[b4b313]: / matlab_xunit_3.1 / matlab_xunit / xunit / TestRunLogger.m

Download this file

105 lines (86 with data), 4.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
%TestRunLogger Collect data (silently) from running test suite
% TestRunLogger is a subclass of TestRunMonitor uses to collect information
% from an executing test component (either a test case or a test suite).
% It maintains a record of event notifications received, as well as any test
% failures or test errors.
%
% TestRunLogger methods:
% testComponentStarted - Log test component started
% testComponentFinished - Log test component finished
% testCaseFailure - Log test case failure
% testCaseError - Log test case error
%
% TestRunLogger properties:
% Log - Cell array of test notification strings
% NumFailures - Number of test failures during execution
% NumErrors - Number of test errors during execution
% NumTestCases - Total number of test cases executed
% Faults - Struct array of test fault information
%
% See also CommandWindowTestRunDisplay, TestRunMonitor, TestSuite
% Steven L. Eddins
% Copyright 2008-2009 The MathWorks, Inc.
classdef TestRunLogger < TestRunMonitor
properties (SetAccess = protected)
%Log Cell array of test notification strings
% Test notification strings include 'TestRunStarted',
% 'TestRunFinished', 'TestComponentStarted', 'TestComponentFinished',
% 'TestCaseFailure', and 'TestCaseError'.
Log
%NumFailures Number of test failures during execution
NumFailures = 0
%NumErrors Number of test errors during execution
NumErrors = 0
%NumTestCases Total number of test cases executed
NumTestCases = 0
%Faults Struct array of test fault information
% Faults is a struct array with the fields Type, TestCase, and
% Exception. Type is either 'failure' or 'error'. TestCase is the
% test case object that triggered the fault. Exception is the
% MException object thrown during the fault.
Faults = struct('Type', {}, 'TestCase', {}, 'Exception', {});
end
properties (SetAccess = private, GetAccess = private)
InitialTestComponent = []
end
methods
function testComponentStarted(self, component)
if isempty(self.InitialTestComponent)
self.InitialTestComponent = component;
self.appendToLog('TestRunStarted');
end
self.appendToLog('TestComponentStarted');
if isa(component, 'TestCase')
self.NumTestCases = self.NumTestCases + 1;
end
end
function testComponentFinished(self, component, did_pass)
self.appendToLog('TestComponentFinished');
if isequal(component, self.InitialTestComponent)
self.appendToLog('TestRunFinished');
end
end
function testCaseFailure(self, test_case, failure_exception)
self.appendToLog('TestCaseFailure');
self.NumFailures = self.NumFailures + 1;
self.logFault('failure', test_case, ...
failure_exception);
end
function testCaseError(self, test_case, error_exception)
self.appendToLog('TestCaseError');
self.NumErrors = self.NumErrors + 1;
self.logFault('error', test_case, ...
error_exception);
end
end
methods (Access = private)
function appendToLog(self, item)
self.Log{end+1} = item;
end
function logFault(self, type, test_case, exception)
self.Faults(end + 1).Type = type;
self.Faults(end).TestCase = test_case;
self.Faults(end).Exception = exception;
end
end
end