PHPUnit - assertion failed but I want to continue testing

后端 未结 4 1336
余生分开走
余生分开走 2021-02-07 10:59
->assertTrue(false);
->assertTrue(true);

First assertion was failed and execution was stopped. But I want to continue the further snippet of code

4条回答
  •  醉酒成梦
    2021-02-07 11:33

    that defeats the point of a unit test. you might want to break it into a few more test methods instead of having a monolithic test method.

    Here is some pseudo-code, as a bad example.

    MyBadTestMethod()
    {
       someResult = MyMethod();
       assertIsCorrect(someResult);
       myResult2 = MyMethod2(someResult);
       assertIsCorrect(myResult2);
    }
    

    MyMethod2 and myResult2 will fail.

    Here is a better example.

    MyTestMethod1()
    {
       someResult = MyMethod();
       assertIsCorrect(someResult);
    }
    MyTestMethod2()
    {
       myResult2 = MyMethod2(someCorrectResult);
       assertIsCorrect(myResult2);
    }
    

提交回复
热议问题