如何发现是否所有assertTrue通过或任何失败



我有一个测试方法

{
    assertTrue("Login failed", somecondition);
    assertTrue("Page not browsing", somecondition);
    assertTrue("Button not found", somecondition);
    //here I want to found whether any assertTrue failed or all are passed
}

我怎么才能做到呢?

嗯,我不确定我是否理解,但是像这样的东西应该可以工作

assertTrue("are my conditions true? {}",condition1 && condition2 && condition3) 

如果你已经到达了

//here I want to found whether any assertTrue failed or all are passed

,那么你肯定知道你已经传递了所有的assertTrue语句。

您都必须使用'assertTrue'方法在JUnit报告中记录条目,并使用您自己的变量来计算您想要的内容

{
   allPassed = True;
   assertTrue("Login failed", somecondition);
   allPassed = allPassed && somecondition;
   assertTrue("Page not browsing", somecondition);
   allPassed = allPassed && somecondition;
   // ...
   assertTrue("All tests succeeded", allPassed);
}

最新更新