changeset 1:0712aa679900 default tip

Package
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Tue, 27 Dec 2011 19:58:37 +0100
parents 33654ef5c7ea
children
files +unittest/TestCase.m +unittest/TestRunner.m TestCase.m TestRunner.m
diffstat 4 files changed, 122 insertions(+), 122 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/+unittest/TestCase.m	Tue Dec 27 19:58:37 2011 +0100
@@ -0,0 +1,53 @@
+classdef TestCase < handle
+  
+  properties    
+    
+  end % properties
+    
+  methods
+    
+    function tests = listTests(self)      
+      tests = {};
+      m = methods(self);
+      for kk = 1:numel(m)
+        if strncmp(m{kk}, 'test_', 5)
+          tests = [ tests m(kk) ];
+        end
+      end
+    end
+
+    function setUpClass(self)
+      
+    end
+    
+    function tearDownClass(self)
+      
+    end    
+    
+    function setUp(self)
+      
+    end
+    
+    function tearDown(self)
+
+    end
+    
+    function test_foo(self)
+      true;
+    end
+    
+    function test_aaa(self)
+      true;
+    end
+    
+    function test_bbb(self)
+      true;
+    end
+    
+    function test_bar(self)
+      assert(false, 'bar');
+    end
+    
+  end % methods
+  
+end
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/+unittest/TestRunner.m	Tue Dec 27 19:58:37 2011 +0100
@@ -0,0 +1,69 @@
+classdef TestRunner < handle
+
+  properties
+
+    testcases = {};
+
+  end % properties
+
+  methods
+
+    function self = TestRunner(testcases)
+      self.testcases = testcases;
+    end
+    
+    function results = run(self)
+
+      failures = {};
+
+      for kk = 1:numel(self.testcases)
+
+        % instance
+        t = feval(self.testcases{kk});
+
+        % setup class
+        t.setUpClass();
+        cleanclass = onCleanup(@()t.tearDownClass());
+
+        for m = t.listTests()
+
+          try
+            % setup test
+            t.setUp()
+            clean = onCleanup(@()t.tearDown());
+          catch ex
+            % something went wrong in test setup code
+            fprintf('E');
+          end
+
+          try
+            % run test
+            feval(m{1}, t);
+            fprintf('.');
+          catch ex
+            % test failure
+            fprintf('F');
+            failures = [ failures { {self.testcases{kk} m{1} ex } }];
+          end
+          % explicitly call cleanup handler
+          clear clean;
+        end
+        % explicitly call class cleanup handler
+        clear cleanclass;
+      end
+      fprintf('\n');
+
+      self.reportFailures(failures)
+
+    end
+
+    function reportFailures(self, failures)
+      for kk = 1:numel(failures)
+        f = failures{kk};
+        fprintf(2, '%s: %s: %s\n%s', which(f{1}), f{1}, f{2}, f{3}.getReport());
+      end
+    end
+
+  end % methods
+
+end
--- a/TestCase.m	Tue Dec 27 19:50:44 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,53 +0,0 @@
-classdef TestCase < handle
-  
-  properties    
-    
-  end % properties
-    
-  methods
-    
-    function tests = listTests(self)      
-      tests = {};
-      m = methods(self);
-      for kk = 1:numel(m)
-        if strncmp(m{kk}, 'test_', 5)
-          tests = [ tests m(kk) ];
-        end
-      end
-    end
-
-    function setUpClass(self)
-      
-    end
-    
-    function tearDownClass(self)
-      
-    end    
-    
-    function setUp(self)
-      
-    end
-    
-    function tearDown(self)
-
-    end
-    
-    function test_foo(self)
-      true;
-    end
-    
-    function test_aaa(self)
-      true;
-    end
-    
-    function test_bbb(self)
-      true;
-    end
-    
-    function test_bar(self)
-      assert(false, 'bar');
-    end
-    
-  end % methods
-  
-end
\ No newline at end of file
--- a/TestRunner.m	Tue Dec 27 19:50:44 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,69 +0,0 @@
-classdef TestRunner < handle
-
-  properties
-
-    testcases = {};
-
-  end % properties
-
-  methods
-
-    function self = TestRunner(testcases)
-      self.testcases = testcases;
-    end
-    
-    function results = run(self)
-
-      failures = {};
-
-      for kk = 1:numel(self.testcases)
-
-        % instance
-        t = feval(self.testcases{kk});
-
-        % setup class
-        t.setUpClass();
-        cleanclass = onCleanup(@()t.tearDownClass());
-
-        for m = t.listTests()
-
-          try
-            % setup test
-            t.setUp()
-            clean = onCleanup(@()t.tearDown());
-          catch ex
-            % something went wrong in test setup code
-            fprintf('E');
-          end
-
-          try
-            % run test
-            feval(m{1}, t);
-            fprintf('.');
-          catch ex
-            % test failure
-            fprintf('F');
-            failures = [ failures { {self.testcases{kk} m{1} ex } }];
-          end
-          % explicitly call cleanup handler
-          clear clean;
-        end
-        % explicitly call class cleanup handler
-        clear cleanclass;
-      end
-      fprintf('\n');
-
-      self.reportFailures(failures)
-
-    end
-
-    function reportFailures(self, failures)
-      for kk = 1:numel(failures)
-        f = failures{kk};
-        fprintf(2, '%s: %s: %s\n%s', which(f{1}), f{1}, f{2}, f{3}.getReport());
-      end
-    end
-
-  end % methods
-
-end