How do You Unit Test a Custom Assert?
我正在编写自己的JUnit Assert? 我该如何测试?
我知道如何为它提供一些会通过的东西以及会使它失败的东西,但是如何为这些东西编写JUnit测试呢?
自定义断言将类似于:
1 2 3 4 5 | public static void assertSomething() { if (!something()) { fail("Expected something, but ..."); } } |
我怎么能抓到那个失败?
例:
1 2 3 4 5 6 7 8 9 10 | @Test(expected = AssertionFailedError.class) public void testMyAssertFails() { assertSomething("valueThatWillFail"); } @Test public void testMyAssertPasses() { assertSomething("valueThatPasses"); //if you reach this line, no failure was thrown } |