开发者

org.springframework.util.Assert shows in my surefire reports as an error, when in fact it should be a failure

开发者 https://www.devze.com 2023-04-12 00:13 出处:网络
However when using the nromal junit assertions, the failures are reported correctly. import static org.junit.Assert.assertEquals;

However when using the nromal junit assertions, the failures are reported correctly.

import static org.junit.Assert.assertEquals; 

Correctly shows up as a failure.

is there anything I can do to make sure spring Assert shows up as failure as well as the normal junit asserts ?

To clarify this

Assert.notNull(null开发者_运维百科);   

Shows as an error in test report, and not a failure.


You are using the wrong Assert class in your unit tests:

  • the org.junit.Assert class is for use in unit tests

  • the org.springframework.util.Assert class is for use in runtime code.

And the practical difference is that they throw different exceptions.

If your unit test is testing whether (say) your bean's afterPropertiesSet() method is calling org.springframework.util.Assert correctly, then this is not a simple JUnit style assertion. Rather, it is a test that IllegalArgumentException is being thrown, and should be tested in the same way that you would test for (say) IOException being thrown at the appropriate point.

0

精彩评论

暂无评论...
验证码 换一张
取 消