Java 有没有一种方法可以内联显示/启用断言?
您能告诉我是否有办法取消并启用junit.framework.Assert命令以忽略它们吗 代码示例只是为了说明我的意思:Java 有没有一种方法可以内联显示/启用断言?,java,selenium,junit,assertions,Java,Selenium,Junit,Assertions,您能告诉我是否有办法取消并启用junit.framework.Assert命令以忽略它们吗 代码示例只是为了说明我的意思: junitOff(); // first method I need help with assertTrue(false); //would normally cause an AssertionError junitOn(); // second method I need help with System.out.println("Broke through asse
junitOff(); // first method I need help with
assertTrue(false); //would normally cause an AssertionError
junitOn(); // second method I need help with
System.out.println("Broke through asserTrue without Error")
我知道可以使用try/catch,但这不是我想要的,因为我不能在断言之后继续执行…我看不到任何方法可以做到这一点。查看您看到的junit代码:
static public void assertTrue(String message, boolean condition) {
if (!condition)
fail(message);
}
而fail()
是:
static public void fail(String message) {
throw new AssertionError(message == null ? "" : message);
}
我认为没有办法打开开关或以其他方式禁用它抛出AssertionError
记录在案,如果你说的是
assert
Java原语,那么它可以被禁用,但只能在编译时使用-ea
开关。打开的命令称为/*
关闭的命令*/
-奇怪的命名约定,但是哦,很抱歉,伙计们-我试图改进代码示例,包括命名约定当然你能改用吗?这可以通过使用-ea参数来打开/关闭。不幸的是,这是不可能的。。我有一个大项目,没有机会改变。如果你告诉我们,你最终想实现什么,这将是有帮助的。