|
|
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertFalse; |
|
|
|
import static org.junit.Assert.assertNotNull; |
|
|
|
import static org.junit.Assert.assertTrue; |
|
|
|
import static org.junit.Assert.fail; |
|
|
|
import static org.junit.Assume.assumeTrue; |
|
|
|
|
|
|
|
import java.lang.reflect.AccessibleObject; |
|
|
|
import java.lang.reflect.Field; |
|
|
@@ -174,4 +175,62 @@ public final class POITestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Rather than adding {@literal @}Ignore to known-failing tests, |
|
|
|
* write the test so that it notifies us if it starts passing. |
|
|
|
* This is useful for closing related or forgotten bugs. |
|
|
|
* |
|
|
|
* An Example: |
|
|
|
* <code><pre> |
|
|
|
* public static int add(int a, int b) { |
|
|
|
* // a known bug in behavior that has not been fixed yet |
|
|
|
* raise UnsupportedOperationException("add"); |
|
|
|
* } |
|
|
|
* |
|
|
|
* {@literal @}Test |
|
|
|
* public void knownFailingUnitTest() { |
|
|
|
* try { |
|
|
|
* assertEquals(2, add(1,1)); |
|
|
|
* // this test fails because the assumption that this bug had not been fixed is false |
|
|
|
* testPassesNow(12345); |
|
|
|
* } catch (UnsupportedOperationException e) { |
|
|
|
* // test is skipped because the assumption that this bug had not been fixed is true |
|
|
|
* skipTest(e); |
|
|
|
* } |
|
|
|
* } |
|
|
|
* |
|
|
|
* Once passing, this unit test can be rewritten as: |
|
|
|
* {@literal @}Test |
|
|
|
* public void knownPassingUnitTest() { |
|
|
|
* assertEquals(2, add(1,1)); |
|
|
|
* } |
|
|
|
* |
|
|
|
* If you have a better idea how to simplify test code while still notifying |
|
|
|
* us when a previous known-failing test now passes, please improve these. |
|
|
|
* As a bonus, a known-failing test that fails should not be counted as a |
|
|
|
* passing test. |
|
|
|
* |
|
|
|
* One possible alternative is to expect the known exception, but without |
|
|
|
* a clear message that it is a good thing to no longer get the expected |
|
|
|
* exception once the test passes. |
|
|
|
* {@literal @}Test(expected=UnsupportedOperationException.class) |
|
|
|
* public void knownFailingUnitTest() { |
|
|
|
* assertEquals(2, add(1,1)); |
|
|
|
* } |
|
|
|
* |
|
|
|
* @param e the exception that was caught that will no longer |
|
|
|
* be raised when the bug is fixed |
|
|
|
*/ |
|
|
|
public static void skipTest(Throwable e) { |
|
|
|
assumeTrue("This test currently fails with " + e, false); |
|
|
|
} |
|
|
|
/** |
|
|
|
* @see #skipTest(Throwable) |
|
|
|
* |
|
|
|
* @param bug the bug number corresponding to a known bug in bugzilla |
|
|
|
*/ |
|
|
|
public static void testPassesNow(int bug) { |
|
|
|
fail("This test passes now. Please update the unit test and bug " + bug + "."); |
|
|
|
} |
|
|
|
} |