Printing debug output to console in Codeception

青春壹個敷衍的年華 提交于 2019-11-30 02:44:32

See Debugging which says

You may print any information inside a test using the codecept_debug function.

And I'm using it in my *Cept class:

codecept_debug($myVar);

Your debug output is only visible when you run with --debug (-v doesn't show it, but -vv and -vvv do):

codecept run --debug

And the output looked like:

Validate MyEntity table insert (MyCept) 
Scenario:
* I persist entity "AppBundle\Entity\MyEntity"

  AppBundle\Entity\MyEntity Object
  (
      [Id:AppBundle\Entity\MyEntity:private] => 1
      [Description:AppBundle\Entity\MyEntity:private] => Description
  )

 PASSED 
\Codeception\Util\Debug::debug($this->em);die();

and run Codeception with --debug flag.

I seem to have found a way around the issue by using a helper class:

class WebHelper extends \Codeception\Module
{
    public function seeMyVar($var){
        $this->debug($var);
    }
}

and calling the class as such:

$foo = array('one','two');
$I->seeMyVar($foo);

then I get the debug output I'm looking for

I see my var "lambda function"
  Array
  (
      [0] => one
      [1] => two
  )

I will accept this as a temporary solution however I would like to keep my assertions clean and not clutter them with var_dumps upgraded to test functions, so if anyone has a conceptually correct solution, please submit

Or you can use the verbosity controlling commands like:

codecept run -vvv

where each v increases the verbosity of the output (very silent by default).

By default Codeception says there was an error but doesn't show it in detail. However according to this blog post adding --debug shows the errors in detail.

codecept run --debug

Short version would be codecept run tests/acceptance/SomeCest.php -d
-d will show you steps and debug

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!