org.springframework.util.Assert 在我的 Surefire 报告中显示为错误,而实际上它应该是失败
但是,当使用正常的 junit 断言时,会正确报告失败。
import static org.junit.Assert.assertEquals;
正确显示为失败。
我能做些什么来确保 spring Assert 显示为失败以及正常的 junit 断言吗?
澄清一下,这
Assert.notNull(null);
在测试报告中显示为错误,而不是失败。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在单元测试中使用了错误的
Assert
类:org.junit.Assert
类用于单元测试org.springframework.util.Assert 类用于运行时代码。
实际的区别在于它们抛出不同的异常。
如果您的单元测试正在测试您的 bean 的
afterPropertiesSet()
方法是否正确调用org.springframework.util.Assert
,那么这不是一个简单的 JUnit 风格断言。相反,它是对抛出IllegalArgumentException
的测试,并且应该以与测试(例如)在适当的点抛出IOException
相同的方式进行测试。You are using the wrong
Assert
class in your unit tests:the
org.junit.Assert
class is for use in unit teststhe
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 callingorg.springframework.util.Assert
correctly, then this is not a simple JUnit style assertion. Rather, it is a test thatIllegalArgumentException
is being thrown, and should be tested in the same way that you would test for (say)IOException
being thrown at the appropriate point.