[b4b313]: / matlab_xunit_3.1 / matlab_xunit / tests / TestFuncHandleTests.m

Download this file

111 lines (96 with data), 4.6 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
105
106
107
108
109
110
111
%TestFuncHandleTests TeseCase class used to test function-handle-based tests
% Steven L. Eddins
% Copyright 2008 The MathWorks, Inc.
classdef TestFuncHandleTests < TestCaseInDir
methods
function self = TestFuncHandleTests(name)
self = self@TestCaseInDir(name, ...
fullfile(fileparts(which(mfilename)), 'helper_classes'));
end
function testSuiteNameAndLocation(self)
test_suite = testFunctionHandlesA();
assertEqual(test_suite.Name, 'testFunctionHandlesA');
assertEqual(test_suite.Location, which('testFunctionHandlesA'));
end
function testOutputs(self)
% Exercise the function-handle test M-file. Output should be a
% two-element cell array of TestCase objects.
test_suite = testFunctionHandlesA();
assertTrue(isa(test_suite, 'TestSuite'));
assertEqual(test_suite.numTestCases(), 2);
end
function testCaseNames(self)
% Verify that Name property of test cases is set properly.
test_suite = testFunctionHandlesA();
assertEqual(test_suite.TestComponents{1}.Name, 'testA');
assertEqual(test_suite.TestComponents{2}.Name, 'testB');
end
function testCaseLocation(self)
% Verify that the Location field of test cases is set properly.
test_suite = testFunctionHandlesA();
expected_location = which('testFunctionHandlesA');
assertEqual(test_suite.TestComponents{1}.Location, expected_location);
assertEqual(test_suite.TestComponents{2}.Location, expected_location);
end
function testPassingTests(self)
% Verify that the expected observer notifications are received in
% the proper order.
logger = TestRunLogger();
suite = testFunctionHandlesA;
suite.run(logger);
assertEqual(logger.Log, ...
{'TestRunStarted', 'TestComponentStarted', ...
'TestComponentStarted', 'TestComponentFinished', ...
'TestComponentStarted', 'TestComponentFinished', ...
'TestComponentFinished', 'TestRunFinished'});
end
function testTestFixture(self)
% Verify that test fixture functions that use testData run without
% error. (See test assertions in testFunctionHandlesB.)
logger = TestRunLogger();
suite = testFunctionHandlesB;
suite.run(logger);
assertEqual(logger.NumFailures, 0);
assertEqual(logger.NumErrors, 0);
end
function testTestFixtureError(self)
% Verify that an exception thrown in a test fixture is recorded as a
% test error.
logger = TestRunLogger();
suite = testFunctionHandlesC();
suite.run(logger);
assertEqual(logger.NumErrors, 2);
end
function testFixtureNoTestData(self)
% Verify that when setupFcn returns no output argument, the test
% functions and the teardown function are called with no inputs.
% (See test assertions in testFunctionHandlesD.)
logger = TestRunLogger();
suite = testFunctionHandlesD();
suite.run(logger);
assertEqual(logger.NumFailures, 0);
assertEqual(logger.NumErrors, 0);
end
function testFailingTest(self)
% Verify that the expected observer notifications are received in
% the proper order for a failing test.
logger = TestRunLogger();
suite = testFunctionHandlesE();
suite.run(logger);
assertEqual(logger.Log, ...
{'TestRunStarted', 'TestComponentStarted', ...
'TestComponentStarted', 'TestCaseFailure', 'TestComponentFinished', ...
'TestComponentFinished', 'TestRunFinished'});
end
function testTeardownFcnButNoSetupFcn(self)
% Verify that a test file works if it has a teardown function but no
% setup function.
logger = TestRunLogger();
suite = testFunctionHandlesTeardownNoSetup();
suite.run(logger);
assertEqual(logger.NumTestCases, 1);
assertEqual(logger.NumFailures, 0);
assertEqual(logger.NumErrors, 0);
end
end
end