Codeception code coverage low - php

I have constructed a pretty complex code suite for a project with Codeception
approx 300 tests, with about 3000 assertions. Now I would like to see my codecoverage.
I ran the following line as per the instruction:
./vendor/bin/codecept run --coverage --coverage-html
I got a very low score (1%). Which is next to impossible considering that all the assertions that I have created does go to the designated spot in the code when the codecoverage states otherwise.
my codeception.yml file looks like this:
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
extensions:
enabled:
- Codeception\Extension\RunFailed
modules:
config:
\Helper\DbWithMigration:
dsn: 'mysql:host=localhost;dbname=travis_test'
user: 'travis'
password: ''
dump: tests/_data/dump.sql
coverage:
enabled: true
include:
- src/*
- console/*
I have tests for the following: unit, acceptance, console, and api.
They all turn green. I'm unsure where I went wrong
UPDATE
Here is my api.suite.yml:
class_name: ApiTester
modules:
enabled:
- \Helper\Api
- REST:
depends: Silex
- Silex:
app: 'tests/_app/bootstrap.php'
- \Helper\DbWithMigration:
cleanup: true
- Asserts
and acceptance.suit.yml:
class_name: AcceptanceTester
modules:
enabled:
- \Helper\Acceptance
- REST:
depends: Silex
- Silex:
app: 'tests/_app/bootstrap.php'
- \Helper\DbWithMigration:
cleanup: true
- Asserts
and as mentioned i'm running off a VM that has ubuntu 14.04 LTS and PHP 5.6.20 with xdebug.

Related

Codeception color report does not work

I have setup codeception to code coverage. I can see the report did run correctly but for some reason code coverage color and percentage did not get calculated. I do see green line which code get executed but it did not show the red.
I have been pulling my hair out and struggle for several days but not be able to figure out the issue. Please help.
Note my /etc/hosts have stagwww.somewhere.com as 127 loop back
my codeception.yml
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
extensions:
enabled:
- Codeception\Extension\RunFailed
my api.suite.yml
class_name: ApiTester
modules:
enabled:
- \Helper\Api
- REST:
url: https://stagwww.somewhere.com
depends: PhpBrowser
coverage:
enabled: true
remote: true
low_limit: 30
high_limit: 60
c3_url: 'https://stagwww.somewhere.com'
remote_context_options:
ssl:
verify_peer: false
verify_peer_name : false
include:
- app\*.php
The "color" setting in your YML is for ANSI color in the terminal. Your screen shot is showing an HTML reporter in the browser - I think the Xdebug codecoverage report. I don't think there is such a setting as "color" in the HTML report, it's a totally different interface.
Color:
No Color:

Empty code coverage

I'm trying to get code coverage for my unit tests with codeception.
When i'm doing vendor/bin/codecept run unit --coverage it displays that :
Classes: 0.00% (0/1)
Methods: 0.00% (0/3)
Lines: 0.00% (0/28)
Although I have tested 1 method over 3.
I have xdebug installed with coverage_enable=On
Here is my codeception.yml config file :
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
extensions:
enabled:
- Codeception\Extension\RunFailed
modules:
config:
Db:
dsn: ''
user: ''
password: ''
dump: tests/_data/dump.sql
coverage:
enable: true
remote: false
include:
- Simplifier/*
exclude:
- vendor/*
I'm trying to test Simplifier/Routing.php
The test is OK, but my coverage is wrong.
Any idea why ?
Thanks.
You made a mistake in setting name.
Change enable: true to enabled: true and code coverage collection will work.
http://codeception.com/docs/11-Codecoverage#Configuration

Codeception autoload: 'WebDriver' is not defined

I have a Symfony2 project, but I cannot get WebDriver configured properly.
I have installed facebook webdriver and codeception with composer:
facebook/webdriver:
versions : * 1.1.3
codeception/codeception:
versions : * 2.2.5
I followed these instructions (and when autoload failed, many other sources without success):
http://codeception.com/11-20-2013/webdriver-tests-with-codeception.html
codeception.yml in project root:
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
extensions:
enabled:
- Codeception\Extension\RunFailed
- WebDriver
config:
WebDriver:
url: 'http://localhost/'
browser: firefox
port: 4444
modules:
config:
Db:
dsn: ''
user: ''
password: ''
dump: tests/_data/dump.sql
I have acceptance tests generated, and when I run codeception, following error occurs:
[Codeception\Exception\ConfigurationException]
Class `WebDriver` is not defined. Autoload it or include into '_bootstrap.php' file of 'tests' directory
I've tried adding this into tests/_bootstrap.php:
require_once __DIR__.'/../vendor/codeception/codeception/src/Codeception/Module/WebDriver.php';
The path above is correct, the php file is found, but the problem persist.
Exactly how the autoloading or bootstrap including should be done?
EDIT:
I made the WebDriver enabling and configuration into tests/acceptance.suite.yml instead of root folder codeception.yml, and got over the problem.
Remains unclear why this happens?
WebDriver is not an extension, but a module.
You have to enable it in the modules section of acceptance.suite.yml file.
modules:
enabled:
- WebDriver
- \Helper\Acceptance
https://github.com/Codeception/Codeception/blob/2.2/tests/web.suite.yml

Codeception remote coverage not merged

I run Codeception acceptance tests and get results:
As you see coverage is 0%
Then I open coverage results in browser from _output/acceptance.remote.coverage/index.html and see total coverage 81.13%
And the questions is: why coverage result not merged and not printed to console? I have to write unit-tests too for cover all methods?
acceptance.suite.yml
class_name: AcceptanceTester
modules:
enabled:
- PhpBrowser:
url: http://127.0.0.1:4444
- \Helper\Acceptance
codeception.yml
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
coverage:
enabled: true
c3_url: http://127.0.0.1:4444
remote: true
whitelist:
include:
- src/*
exclude:
- tests/*
extensions:
enabled:
- Codeception\Extension\RunFailed
Run tests command
codecept run --coverage --coverage-xml --coverage-html --coverage-text --fail-fast
Versions
Codeception PHP Testing Framework v2.2.2
Powered by PHPUnit 5.4.6 by Sebastian Bergmann and contributors.
Codeception won't merge your results, as stated in the documentation:
But if you run tests on different server [...] a single option remote should be added to config. [...]
In this case remote Code Coverage results won’t be merged with local ones, if this option is enabled. Merging is possible only in case a remote and local files have the same path. But in case of running tests on a remote server we are not sure of it.
Maybe you can do it manually by using phpcov.

Codeception is not rolling back DB changes in Laravel 5?

I am new to codeception and I am using it to test a web service I am creating in laravel 5. So my main config file looks like so:
codeception.yml
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
extensions:
enabled:
- Codeception\Extension\RunFailed
modules:
config:
Db:
dsn: 'mysql:host=localhost;dbname=carparts'
user: 'root'
password: 'SomePassword'
dump: tests/_data/dump.sql
And the suite file called api.suite.yml looks like so:
class_name: ApiTester
modules:
enabled:
- Laravel5
- REST:
url: http://localhost:8000/api/
depends: PhpBrowser
config:
Laravel5:
cleanup: true
environment_file: .env.testing
I also copy pasted the whole dump of my database carparts into the dump.sql file but still when I run the tests, I still see new users created which are being created in the tests. What am I missing? Where am I going wrong?
So I did not know that in order to rollback the DB I need to enable the Db module:
class_name: ApiTester
modules:
enabled:
- Laravel5
- Db
- REST:
url: http://localhost:8000/api/
depends: PhpBrowser
config:
Laravel5:
cleanup: true
environment_file: .env.testing
And that did it.

Categories