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.
Related
I'm writing an acceptance test suite and I have to make the environment easily configurable, but for this to work I need to be able to merge two or more environments (geoLocation, browser, os, URLs).
If I run: .\codecept run tests\acceptance\acceptanceTestCest --env firefox the tests start running without issues with any environment I choose.
Now my problem is that if I try to merge the environments: .\codecept run tests\acceptance\acceptanceTestCest --env firefox,US I get the following message:
In Configuration.php line 306:
[Codeception\Exception\ConfigurationException]
Suite tests\acceptance\acceptanceTestCest.php was not loaded
And if I try to merge more than two environments I get this message:
Too many arguments, expected arguments "command" "suite" "test".
This is how my acceptance.suite.yml looks like:
actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: http://localhost
- REST:
depends: PhpBrowser
url: 'http://localhost/api/'
- \Helper\Acceptance
config:
WebDriver:
host: 'user:key#hub.browserstack.com'
port: 3214
browser: chrome
capabilities:
os: Windows
os_version: 10
browserstack.local: true # for local testing
env:
AU:
modules:
config:
WebDriver:
capabilities:
browserstack.geoLocation: AU
US:
modules:
config:
WebDriver:
capabilities:
browserstack.geoLocation: US
CA:
modules:
config:
WebDriver:
capabilities:
browserstack.geoLocation: CA
firefox:
modules:
config:
WebDriver:
browser: firefox
safari:
modules:
config:
WebDriver:
browser: safari
I looked everywhere for this issue and I did not find anyone that even encountered it. The closest thing I found was that tests would be ran only with the second environment.
I'm new to Codeception and probably I am missing something.
I read the documentation on https://codeception.com/docs/07-AdvancedUsage#Environments and I don't seem to do anything wrong from there.
Codeception version is 2.4.5
PHP version is 7.2.8
Operating system: Windows Server 2012
Installation type: Composer 1.7.2
Things I tried:
Put the environments in _envs folder.
Put the environments in codeception.yml
Also I have the project on Jenkins as well and merging environments works perfectly there, but if I try to download the exact same project and run it locally it still doesn't 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:
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
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
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.