SerialTest (array of anonymous classes) + TestCas
[nikiroo-utils.git] / src / be / nikiroo / utils / test / TestCase.java
index 4e7d3800c5a588bf6a1b06f341bfc5d3c2c8c2ac..85a65d7a8cc83e716d499ea201efd481295d1867 100644 (file)
@@ -38,6 +38,15 @@ abstract public class TestCase {
                this.name = name;
        }
 
+       /**
+        * This constructor can be used if you require a no-param constructor. In
+        * this case, you are allowed to set the name manually via
+        * {@link TestCase#setName}.
+        */
+       protected TestCase() {
+               this("no name");
+       }
+
        /**
         * Setup the test (called before the test is run).
         * 
@@ -65,6 +74,20 @@ abstract public class TestCase {
                return name;
        }
 
+       /**
+        * The test name.
+        * 
+        * @param name
+        *            the new name (internal use only)
+        * 
+        * @return this (so we can chain and so we can initialize it in a member
+        *         variable if this is an anonymous inner class)
+        */
+       protected TestCase setName(String name) {
+               this.name = name;
+               return this;
+       }
+
        /**
         * Actually do the test.
         * 
@@ -88,12 +111,28 @@ abstract public class TestCase {
         * 
         * @param reason
         *            the failure reason
+        * 
         * @throws AssertException
         *             every time
         */
        public void fail(String reason) throws AssertException {
+               fail(reason, null);
+       }
+
+       /**
+        * Force a failure.
+        * 
+        * @param reason
+        *            the failure reason
+        * @param e
+        *            the exception that caused the failure (can be NULL)
+        * 
+        * @throws AssertException
+        *             every time
+        */
+       public void fail(String reason, Exception e) throws AssertException {
                throw new AssertException("Failed!" + //
-                               reason != null ? "\n" + reason : "");
+                               reason != null ? "\n" + reason : "", e);
        }
 
        /**