Tre*_*iss 14 java testing junit
当故意使测试用例失败时(例如,当没有抛出异常时)我看到人们同时使用fail()和assertTrue(false).使用其中一个有什么好处吗?
try {
//method call that should throw exception
fail("oops");
} catch (Exception e) {}
Run Code Online (Sandbox Code Playgroud)
与
try {
//method call that should throw exception
assertTrue("oops", false);
} catch (Exception e) {}
Run Code Online (Sandbox Code Playgroud)
BeR*_*ive 13
expected在@Test注释中使用JUnit的参数
@Test(expected = ArithmeticException.class)
public void divisionWithException() {
int i = 1/0;
}
Run Code Online (Sandbox Code Playgroud)
如果ArithmeticException没有抛出,这将失败.
| 归档时间: |
|
| 查看次数: |
5652 次 |
| 最近记录: |