phpunit - 有关风险测试的帮助

bob*_*c82 6 php testing phpunit

我正在为网站实施一些测试.在特定测试中,出现了以下结果:

{
"event": "test",
"suite": "Example_V_test",
"test": "Example_V_test::test_3",
"status": "error",
"time": 13.469105958939,
"trace": [
    {
        "file": "\/opt\/lampp\/htdocs\/buy\/application\/tests\/phpunit.phar",
        "line": 569,
        "function": "main",
        "class": "PHPUnit_TextUI_Command",
        "type": "::"
    }
],
"message": "Risky Test: Test code or tested code did not (only) close its own output buffers",
"output": ""
}R                                                                 3 / 3 (100%)

Time: 25.76 seconds, Memory: 59.25MB

There was 1 risky test:

1) Example_V_test::test_3
Test code or tested code did not (only) close its own output buffers

/opt/lampp/htdocs/buy/application/tests/phpunit.phar:569

OK, but incomplete, skipped, or risky tests!
Run Code Online (Sandbox Code Playgroud)

我的问题是:如何找到导致这个"问题"的代码行?

JSc*_*her 9

如果PHPUnit检测到测试方法结束时的输出缓冲级别与开头的级别不同,则会报告该消息.这是因为它使用自己的输出缓冲区并检查测试是否产生无输出.

因为PHPUnit中没有选项可以忽略这一点,所以你需要找到代码中的输出缓冲启动但未结束(或结束太多)并修复它的原因.

这可能真的很难实现,因为没有提示,输出缓冲开始,但您可以使用源代码(和库)上的全文搜索来识别候选.然后查找异常,这可能会破坏正常的程序流,因此阻止ob_end_flush()(或类似)被调用.

  • 现在效果很好,谢谢!我在缓冲区内发生了中止/死亡,这导致了测试脚本中的错误。之前:`ob_start(); 中止(404);ob_get_clean();` 解决方案:`ob_start(); ob_end_flush(); 中止(404);ob_get_clean();` (2认同)

Kra*_*ray 6

具体到Test code or tested code did not (only) close its own output buffers

最近遇到了这个。

最初这个问题是这样的,答案对我来说是一个解决方案。但是,我不喜欢这个解决方案。发生这种情况有一个更深层次的原因,而在我编写的数百个测试中,只有一个......

经过更多的挖掘后,我能够找到我的问题源于刀片模板中的@section()and call 。@endsection

不知何故,由于错误地敲击了键盘,并留下了一个随机的键。这不会在视觉上造成问题,也不会在页面呈现时给最终用户带来任何危险信号,因此不会被注意到。

就我而言——我的错误是

@section('sudo')
...
@endsection2
Run Code Online (Sandbox Code Playgroud)

删除2固定的原始问题并允许我删除 hacky 解决方案

//        // start hacky
//            ob_start();
//            ob_end_flush();
//            ob_get_clean();
//        // end hacky
Run Code Online (Sandbox Code Playgroud)

附:这可能只能解决一部分遇到这个问题的人的问题。抱歉,如果它不能解决您的问题:)

  • 如果你不说的话,我真的永远不会找到这个,所以谢谢你。 (2认同)