Code covered by the BSD License  

Highlights from
MATLAB xUnit Test Framework

image thumbnail

MATLAB xUnit Test Framework

by

 

31 Jan 2009 (Updated )

MATLAB xUnit is a unit test framework for MATLAB code.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

TestRunLoggerTest
%TestSuiteTest Unit tests for TestSuite class

% Copyright 2013 The MathWorks, Inc.

classdef TestRunLoggerTest < TestCaseInDir

   methods
      function self = TestRunLoggerTest(name)
         self = self@TestCaseInDir(name, ...
             fullfile(fileparts(which(mfilename)), 'helper_classes'));
      end
      
      function testTwoPassingTests(self)
         logger = TestRunLogger;
         suite = TestSuite('TwoPassingTests');
         suite.run(logger);
         
         assertEqual(logger.Log, ...
             {'TestRunStarted', ...
             'TestComponentStarted', ...
             'TestComponentStarted', 'TestComponentFinished', ...
             'TestComponentStarted', 'TestComponentFinished', ...
             'TestComponentFinished', ...
             'TestRunFinished'});
         
         assertEqual(logger.NumTestCases, 2);
         assertEqual(logger.NumFailures, 0);
         assertEqual(logger.NumErrors, 0);
         assertTrue(isempty(logger.Faults));
      end
      
      function testFailingTestCase(self)
         logger = TestRunLogger;
         suite = TestSuite('FailingTestCase');
         suite.run(logger);
         
         assertEqual(logger.Log, ...
             {'TestRunStarted', ...
             'TestComponentStarted', ...
             'TestComponentStarted', 'TestCaseFailure', 'TestComponentFinished', ...
             'TestComponentFinished', ...
             'TestRunFinished'});
         
         assertEqual(logger.NumTestCases, 1);
         assertEqual(logger.NumFailures, 1);
         assertEqual(logger.NumErrors, 0);
         assertEqual(numel(logger.Faults), 1);
         assertEqual(logger.Faults(1).Type, 'failure');
      end
      
   end

end

Contact us