使用 simpletest 框架进行 xdebug 代码覆盖率分析
我正在使用 simpletest 框架进行单元测试,并使用 xdebug 进行代码覆盖率报告。让我解释一下我的问题:
- 我有一个要测试的类,假设类的名称是 pagination.php。
- 我编写另一个类进行测试。我写了两个测试用例来测试分页类。
- 两个测试用例中有大约 12 个断言,这给了我正确的结果“通过”。
- 现在我想生成代码覆盖率报告,为此我使用 xdebug 来显示我的测试用例是否覆盖了所有代码。我使用 xdebug_start_code_coverage() 函数,为了显示结果,我使用 xdebug_get_code_coverage() 函数。
现在的问题是,当我打印 xdebug_get_code_coverage() 时,它给我一个带有文件名、行号和执行时间的二维关联数组。结果是这样的:
array
'path/to/file/pagination.php' =>
array
11 => int 1
113 => int 1
第 11 行是课程开始,第 113 行是课程结束。我不知道为什么它不进入类内部,也不知道为什么它不提供类函数的语句覆盖率。然而,我的测试用例看起来不错,我知道所有条件和分支覆盖都有效。
如果您在这方面帮助我并指导我如何解决这个问题,我将非常感激。
也许我在这里错过了一些东西。如果您想要更多东西,请告诉我。
I am doing unit testing with simpletest framework and using xdebug for code coverage reports. let me explain you my problem:
- I have a class which I want to test lets assume name of class is pagination.php.
- I write another class for testing. I wrote two test cases to test pagination class.
- there are around 12 assertion in two test cases which giving me correct result "Pass".
- Now I want to generate code coverage report, for this I use xdebug to show that my test cases covering all code or not. I use xdebug_start_code_coverage() function and for showing result I use xdebug_get_code_coverage() function.
Now the problem is that, when I print xdebug_get_code_coverage() Its give me 2 dimension assosiative array with filename, line no and execution times. the result is like this:
array
'path/to/file/pagination.php' =>
array
11 => int 1
113 => int 1
line 11 is start of class and line 113 is end of class. I don't know why it is not going inside class and why it is not giving the statement coverage for class functions. However, my test cases looks ok to me and I know all condition and branching covering are working.
I will really appreciate if you help me in this regard and guide me how to solve this problem.
Maybe I missed something here. If you want something more please let me know.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我为一个带有调用方法的类实现了 XDebug-CC,它工作得很好。虽然我不得不说我对这个工具如何定义“可执行代码”有点困惑,但它肯定考虑到了方法。
您可以检查 xdebug_start_code_coverage() 和 xdebug_get_code_coverage() 的位置,因为它们必须在最开始和最后调用。
您还可以检查您的 XDebug 版本,因为自该功能发布以来,准确性有所提高。
最佳
拉斐尔
I implemented an XDebug-CC for a class with invoked methods and it works fine. Though I have to say that I am a bit confused about how this tool defines "executable code", it definitely takes account of methods.
You might check the location of your xdebug_start_code_coverage() and xdebug_get_code_coverage(), as those have to be invoked at the very beginning and the very end.
Also you might check your XDebug-version, as there has been some accuracy-improvements since the feature has been released.
Best
Raffael
SimpleTest 有一个相当容易设置的覆盖范围扩展。 IIRC 它仅在 svn 中,而不是正常的打包下载。 (通常在 simpletest/extensions/coverage/ 中)
您可以查看有关如何实现它的示例的文章:
http://www.acquia.com/blog/calculate-test-coverage
http://drupal.org/node/1208382
SimpleTest has a coverage extension that is fairly easy to setup. IIRC it is only in svn and not the normal packaged downloads. (normally in simpletest/extensions/coverage/)
You can see articles for examples of how to implement it:
http://www.acquia.com/blog/calculating-test-coverage
http://drupal.org/node/1208382