Junit测试方法查询
public void testNullsInName() {
fail("sample failure");
Person p = new Person(null, "lastName");
assertEquals("lastName", p.getFullName());
p = new Person("Tanner", null);
assertEquals("Tanner ?", p.getFullName());
}
我很难理解 Junit 中的失败。 有人可以告诉我上面方法中的失败有什么用吗? (我想知道它在那里负责做什么)
通常如果我想在上面的代码中添加下面的行。我该如何添加
Person p = new Person(null, "lastName"); // After this statement
if(p==null)
{
// then dont proceed further to the further execution
// Show the Junit Test case as PASS .
}
请帮助我。
public void testNullsInName() {
fail("sample failure");
Person p = new Person(null, "lastName");
assertEquals("lastName", p.getFullName());
p = new Person("Tanner", null);
assertEquals("Tanner ?", p.getFullName());
}
I have difficulty in understanding fail in Junit .
Could anybody please tell me what is the use of fail in the above method ??
( I want to know what it is responsible to do there )
And typically if i want to add this below line also in the above code . how could i add
Person p = new Person(null, "lastName"); // After this statement
if(p==null)
{
// then dont proceed further to the further execution
// Show the Junit Test case as PASS .
}
Please help me .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一种情况下的
fail("sample failure");
语句将导致在运行该语句时测试报告为失败,原因是“sample failure”。不知道为什么它被放置为测试用例中的第一个语句,因为它会导致测试立即失败并且其余语句永远不会执行。对于第二种情况,只需从方法返回即可使测试通过。The
fail("sample failure");
-statement in the first case will cause the test to be reported as failed with reason "sample failure" when the statement is run. No idea why it's placed as first statement in the test case, as it will cause the test to fail immediately and the rest of the statements are never executed. As for the second case, simplyreturn
ing from the method will cause the test to pass.