When using PHPUnit, you can annotate a test case with @covers SomeClass::someMethod
to ensure that only code inside of that method is recorded as covered when running the test. I like to use this feature because it helps me separate code that was incidentally executed during a test from code that was actually tested.
After using Codeception to implement some acceptance tests for my project, I decided I would rather use it than PHPUnit to run my unit tests. I would like to remove PHPUnit from the project if possible.
I am using Codeception's Cest format for my unit tests, and the @covers
and @codeCoverageIgnore
annotations no longer work. Code coverage reports show executed code outside of the methods specified with @covers
as covered. Is there any way to mimic that "strict coverage" functionality using Codeception?
Edit: I have submitted an enhancement request to the Codeception project's Github.
It turns out that strict coverage was not possible using Cest-format tests when I asked the question. I have implemented it and the pull request has been merged.
For anyone migrating tests from PHPUnit and looking for this feature as I was, this means that a later release of Codeception should provide support for @covers
, @uses
, @codeCoverageIgnore
, and other related test annotations.
The current version (2.2.4
at the time this was written) doesn't support it but 2.2.x-dev
should.