嗨,我有以下JUnit测试有线JUnit测试断言
@Test
public void testTest() {
AddressEntity entity = null;
assert (entity.getStatus() == StatusType.REMOVED);
}
在eclipse它走向绿色,行家发现错误。
为什么在eclipse中不会抛出错误?
嗨,我有以下JUnit测试有线JUnit测试断言
@Test
public void testTest() {
AddressEntity entity = null;
assert (entity.getStatus() == StatusType.REMOVED);
}
在eclipse它走向绿色,行家发现错误。
为什么在eclipse中不会抛出错误?
Maven默认启用断言。 See surefire official doc
Eclipse默认情况下不启用断言。您可以通过在JVM选项中添加-ea来启用它们。 See Oracle official doc
在你考虑一个UnitTest的时候,你应该使用Assert.assertSame()。 See JUnit official doc
谢谢我将来会考虑这个 – wutzebaer 2012-08-03 19:23:56
无法找到eclipse忽略java的断言关键字的真正原因。
但我建议你不要在你的JUnit中使用java的assert。这不是一个内容丰富的断言和不好的做法。 使用org.junit.Assert之一声明。它可以在eclipse/maven中使用。
祝你好运。
你是如何在eclipse中运行的? – Mark 2012-08-03 13:54:55
rightclick - >运行 - > junit – wutzebaer 2012-08-03 13:58:37