assert !destinationDirectory: "Destination directory is required to create an archive"
这是否意味着如果destinationDirectory为null,则应该使用AssertionError返回它旁边的消息?
答案 0 :(得分:2)
是。您可以通过简单地运行测试来判断。运行这个:
assert false
你得到:
Assertion failed:
assert false
at org.codehaus.groovy.runtime.InvokerHelper.assertFailed(InvokerHelper.java:386)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.assertFailed(ScriptBytecodeAdapter.java:658)
at ConsoleScript5.run(ConsoleScript5:1)
....
但是,这个:
assert false: "This is false!"
给出:
java.lang.AssertionError: This is false!. Expression: false
at org.codehaus.groovy.runtime.InvokerHelper.assertFailed(InvokerHelper.java:388)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.assertFailed(ScriptBytecodeAdapter.java:658)
at ConsoleScript6.run(ConsoleScript6:1)
我找不到要验证的文档,但我可能只是错过了它。 It also looks like此格式的作用相同:assert test, "message"
。