类似于 @covers 的任何其他替代方法,用于标记单元测试中覆盖了类的特定方法

发布于 2024-11-04 15:44:16 字数 216 浏览 0 评论 0原文

请注意,我没有在单元测试中实例化我的代码,而是使用curl 来测试Web 服务操作,然后根据预期值断言实际结果。我的测试没有任何问题。我只是想要一种方法来表明该类已包含在 PHPUnderControl 的“CodeCoverage”中。我尝试了 @covers - 它只是将类放在类的代码覆盖率列表中,但将代码覆盖率设置为 0 拉低了我的整体覆盖率。我想知道是否有一种方法可以明确表明单元测试应该涵盖类中的少数方法。

Please note that I am not instantiating my code in my unit test rather I am using curl to test a web service operation and then asserting the actual result against expected value. I have no issues with my testing. I just want a way to show that the class is covered in the 'CodeCoverage' of PHPUnderControl. I tried @covers- it just puts up the class in the Code Coverage list of classes but gives the code coverage as 0 pulling down my overall coverage. I wonder if there is a way to indicate explicitly that a unit test should cover few methods in a class.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

檐上三寸雪 2024-11-11 15:44:16

使用 @covers 标记测试告诉 PHPUnit 在该测试期间使用 xdebug 来跟踪该区域的代码覆盖率。它没有声明代码已被覆盖。我假设被测试的代码在通过 httpd、Apache 或其他 HTTP 方法调用的单独 PHP 进程下运行。

如果您能找到一种方法在测试中绕过 curl 并直接调用代码,那么覆盖率就会被跟踪。这样只会留下请求层未被覆盖,这会让你更接近。或者您需要找到一种方法来模拟传入您的 Web 服务的相同调用。

Marking a test with @covers tells PHPUnit to use xdebug to track the code coverage in that area during that test. It does not state that the code is covered. I assume that the code under test is running under a separate PHP process invoked via httpd, Apache, or some other HTTP method.

If you can find a way to bypass curl from within your test and call the code directly, the coverage would get tracked. That would leave only the request layer uncovered which gets you closer. Or you need to find a way to simulate the same calls that come in to your web service.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文