我不熟悉 JUnit,所以不确定这是否是 assertTrue(b_exception);
的问题,因为如果我输入 System.out.println("something");
那里,它会打印出“东西”...谢谢!
注意是伪代码,注意逻辑
b_exception = false;
try{
somethingThrowError();
}catch(Error e){
b_exception = true;
}
assertTrue(b_exception);
最佳答案
我不知道你的代码有什么问题,因为你没有说明它是如何未能满足你的期望的,但是测试抛出异常的正确习惯是使用 JUnit 4 的注释:
@Test(expected=SpecificError.class)
public void testError(){
somethingThrowError();
}
关于java - 谁能告诉我这个伪代码有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8107687/