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

ThrowsExceptionTest
% Copyright 2013 The MathWorks, Inc.

classdef ThrowsExceptionTest < TestCaseInDir
    
    methods
        function self = ThrowsExceptionTest(methodName)
            self = self@TestCaseInDir(methodName, ...
                fullfile(fileparts(which(mfilename)), 'helper_classes'));
        end
        
        function testPassingTest(self)
            logger = TestRunLogger();
            TestSuite('PassingExceptionTest').run(logger);
            assertTrue((logger.NumTestCases == 1) && ...
                (logger.NumFailures == 0) && ...
                (logger.NumErrors == 0), ...
                'Passing exception test should have no failures or errors');
        end
        
        function testNoExceptionTest(self)
            logger = TestRunLogger();
            TestSuite('ExceptionNotThrownTest').run(logger);
            assertTrue(strcmp(logger.Faults(1).Exception.identifier, ...
                'assertExceptionThrown:noException'), ...
                'Fault exception should be throwsException:noException');
        end
        
        function testWrongExceptionTest(self)
            logger = TestRunLogger();
            TestSuite('WrongExceptionThrownTest').run(logger);
            assertTrue(strcmp(logger.Faults(1).Exception.identifier, ...
                'assertExceptionThrown:wrongException'), ...
                'Fault exception should be throwsException:wrongException');
        end
        
    end
    
    
end

Contact us