admin管理员组文章数量:1123085
JUnit 5 introduced lambdas for messages of failed assertions. So the message is only evaluated after a failed assertion.
For example, if I have this in TestNG:
Optional<Data> data = ...;
assertTrue(data.isEmpty(), data.get().toString());
it will cause an exception if data
is isEmpty, although the test should pass. In JUnit 5 I can use this instead:
Optional<Data> data = ...;
assertTrue(data.isEmpty(), () -> data.get().toString());
So data.get().toString()
is only run if it has data. No exception happens, the unit-test runs normal.
I know I can mix TestNG and JUnit, but I would prefer not to do this, because it can become confusing (for example, the parameter order for many identical named assertions is switched).
Is there any possibility to do this in TestNG, maybe with a another library, which extends TestNG?
本文标签: junit5How to use lambdas for TestNG failed assertion messagesStack Overflow
版权声明:本文标题:junit5 - How to use lambdas for TestNG failed assertion messages? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736548407a1944480.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论