comparison TestRunner.m @ 0:33654ef5c7ea

Import
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Tue, 27 Dec 2011 19:50:44 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:33654ef5c7ea
1 classdef TestRunner < handle
2
3 properties
4
5 testcases = {};
6
7 end % properties
8
9 methods
10
11 function self = TestRunner(testcases)
12 self.testcases = testcases;
13 end
14
15 function results = run(self)
16
17 failures = {};
18
19 for kk = 1:numel(self.testcases)
20
21 % instance
22 t = feval(self.testcases{kk});
23
24 % setup class
25 t.setUpClass();
26 cleanclass = onCleanup(@()t.tearDownClass());
27
28 for m = t.listTests()
29
30 try
31 % setup test
32 t.setUp()
33 clean = onCleanup(@()t.tearDown());
34 catch ex
35 % something went wrong in test setup code
36 fprintf('E');
37 end
38
39 try
40 % run test
41 feval(m{1}, t);
42 fprintf('.');
43 catch ex
44 % test failure
45 fprintf('F');
46 failures = [ failures { {self.testcases{kk} m{1} ex } }];
47 end
48 % explicitly call cleanup handler
49 clear clean;
50 end
51 % explicitly call class cleanup handler
52 clear cleanclass;
53 end
54 fprintf('\n');
55
56 self.reportFailures(failures)
57
58 end
59
60 function reportFailures(self, failures)
61 for kk = 1:numel(failures)
62 f = failures{kk};
63 fprintf(2, '%s: %s: %s\n%s', which(f{1}), f{1}, f{2}, f{3}.getReport());
64 end
65 end
66
67 end % methods
68
69 end