I have an application with different modules. For each module, there are separate tests written which are divided in different suites.
For example in tests/Custom/codeception.yml
namespace: Test\Custom
paths:
tests: .
data: _data
support: _support
log: _output
coverage:
enabled: true
remote: false
whitelist: { include: ['../../../../src/*'] }
suites:
Business:
path: Business
...
View:
path: View
....
So every module has its own codeception.yml.
To have one "master config" there is a codeception.yml in the first level of the test folder which is including all the subfolder module yml with
namespace: Test
actor: Tester
include:
- tests/*
...
When running a build caused by a branch update in the repository we usually don't want to run other tests than business because they are slow and fragile.
For this i try to run codecept run Business and expect, that just the Business suites from the included files will be executed.
But this will not work, instead i get the error message
Suite 'Business' could not be found
But when i run one module explicit with Business suite
codecept run -c tests/Custom Business
it works.
My first assumption was, that the files get not proper included to the master yml so i tried the general call
codecept run
and it works! But this unfortunately runs all suites.
So, why the suites cant be seen by the master codeception.yml? How can i run all tests Business suites without pointing explicit to the module path?
Thanks
Related
In order to record my tests I run codeception with this command
codecept --ext Recorder
However I can't manage to record anything. Does one see what I'm doing wrong?
Codeception Recorder is disabled, no available modules:
gravityflow/codeception.dist.yml
gravityflow/plugin/tests/acceptance-tests/acceptance.suite.yml:
You're using the WordPress module, WPWebDriver. You need to tell recorder it's active. Put this in your main codeception.yml file:
extensions:
enabled:
- Codeception\Extension\RunFailed
- Codeception\Extension\Recorder
config:
Codeception\Extension\Recorder:
delete_successful: false
module: WPWebDriver
I have set up a functional test following the tutorials at:
http://codeception.com/docs/04-FunctionalTests
http://codeception.com/docs/modules/Symfony
http://codeception.com/09-04-2015/using-codeception-for-symfony-projects.html
The main difference is that I've set up Codeception the traditional way because I don't want to mix test code with project code.
This is my functional test (I know it's not actually testing anything):
<?php
class MyFirstCest {
public function _before(FunctionalTester $I) {
}
public function _after(FunctionalTester $I) {
}
// tests
public function tryToTest(FunctionalTester $I) {
$I->amOnPage('/app/login/');
}
}
When I run the functional test I get:
[RuntimeException] Call to undefined method FunctionalTester::amOnPage
When I rebuild Codeception, I get:
Building Actor classes for suites: acceptance, functional, unit
-> AcceptanceTesterActions.php generated successfully. 0 methods added
\AcceptanceTester includes modules: PhpBrowser, \Helper\Acceptance
-> FunctionalTesterActions.php generated successfully. 0 methods added
\FunctionalTester includes modules:
-> UnitTesterActions.php generated successfully. 0 methods added
\UnitTester includes modules: Asserts, \Helper\Unit
The critical part seems to be \FunctionalTester includes modules: which is empty.
My functional.suite.yml file looks like this:
actor: FunctionalTester
modules:
- Symfony:
app_path: 'app'
environment: 'local_test'
class_name: FunctionalTester
modules:
enabled:
- Symfony2:
app_path: 'path/to/app'
var_path: 'path/to/app'
- Doctrine2:
depends: Symfony2
- \Helper\Functional
- PhpBrowser:
url: dev.hmr-app
- \AcmeBundle\Helper\Functional
where the Symfony app lives in path/to/app. I know there's a lot of junk in there, but that's because I've been experimenting, trying to get it to work.
What am I doing wrong?
I think that your problem is that you have
modules:
- Symfony:
app_path: 'app'
environment: 'local_test'
in the config.
That section is completely misplaced and it probably is causing you issues.
Please remove it and rename Symfony2 with Symfony in enabled section.
Also make sure that you are using the latest version of Codeception.
I try to configure unit-tests suite in Codeception. When I run suite Codeception fail with error Fatal error: Cannot re-declare class rest\tests\UnitTester. With debugger I located places where it loads class first and second time.
First time Codeception load Actor in Codeception\Test\Loader\Gherkin during adding steps to loader.
Second time it initialize Actor instance for class with tests. In second place this class must be already included, but again loader is triggered. Here error appear.
Class is loaded with Codeception loader. At first I think that it was caused by namespace, but UnitTester is only one class in namespace. My .yml files a listed below. I would be very grateful for help.
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
modules:
config:
Yii2:
configFile: 'config/test-local.php'
unit.suite.yml:
class_name: UnitTester
modules:
enabled:
- Yii2
- Asserts
I found a reason of this problem. My codeception.yml for this tests missing namespace param when classes in test folder was under namespace. This caused my problem.
I have a number of tests written for a Laravel 5.1 application, and I'm currently using PHPUnit to run the tests. I'm attempting to investigate codeception as we have other applications that aren't built on Laravel, so codeception looks like the easiest way to get a similar interface for testing.
We have a reasonably large team, so I would prefer to use a single consistent command for testing across all projects instead of some using codecept and some using phpunit.
Here's what I've tried as my codeception.yml:
actor: Tester
paths:
tests: tests
log: storage/codeception/_output
data: storage/codeception/_data
support: storage/codeception/_support
envs: storage/codeception/_envs
modules:
enabled:
- Laravel5:
environment_file: .env
But I get this response:
$ codecept run
Codeception PHP Testing Framework v2.1.4
Powered by PHPUnit 4.8.18 by Sebastian Bergmann and contributors.
[RuntimeException]
Suite '' could not be found
So my question is this:
How do I convince codeception to run my existing PHPUnit tests with as little modification as possible?
After a lot of time, I found out that it's possible, but you have to make some modifications to how your tests are laid out. The bonus, though, is that it doesn't stop you from just running PHPUnit itself.
For posterity, here's how to do it:
Move your unit tests and TestCase.php into a folder named unit under the tests folder.
It should look like this:
tests/
tests/unit/
tests/unit/MyUnitTest.php
tests/unit/TestCase.php
Add the unit.suite.yml file in the tests/ folder.
The contents should look something like this:
modules:
enabled:
- Laravel5:
environment_file: .env.testing
Update your composer.json to with the correct folder for the testing classmap
In your autoload-dev section:
"classmap": [
"tests/unit/TestCase.php"
]
Update your TestCase.php to load bootstrap.php from the correct folder.
This should be in the createApplication() method at the top of TestCase.php
public function createApplication()
{
// $app = require __DIR__ . '/../bootstrap/app.php';
$app = require __DIR__ . '/../../bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
return $app;
}
Finally, run composer dump-autoload, and codeception should run. As a bonus, phpunit should also still run.
I have the following folder structure, I want multiple test suites to exist in different directories.
- project
- app
- app-A
- tests
- (functional tests here)
- app-B
- tests
- (functional tests here)
- domains
- domain-A
- tests
- (unit tests here)
- domain-B
- tests
- (unit tests here)
1. create codeception.yml file in the root directory of your project
2. past the following in that file:
include:
-
paths:
log: log
settings:
colors: true
3. generate the some test suites in on their sub directories:
codecept bootstrap /.../src/Domains/User --namespace user
codecept bootstrap /.../src/Application/Cms --namespace cms
4. update the codeception.yml of the root directory by including the path to the test suite under the includes.
include:
- src/Domains/User
- src/Application/Cms
5. generate some tests
codecept generate:cept --config src/Domains/User unit testB
codecept generate:cept --config src/Applications/Cms functional testA
6. run the tests
codecept run