I m using symfony3 with codeception
I have a hierarchy like this in my project
tests/
UserBundle/
mySuperTest.php
unit/
myUnitTest.php
functional/
myFunctionalTest.php
When i run
php bin/codecept run
it only show me the running of myUnitTest and myFunctionalTest, but not mySuperTest which is an extend of symfony/webTestCase.
How to run all my total suites including UserBundle ?
regards.
Related
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
I am using the cakephp test (php unit test) with xdebug to run the server side code and monitor the output from the terminal rather than using it for validation.
So, every time, i want to run some particular lib/controller/model method from the terminal and see the output, i have to comment out the other test case functions.
I know this might not be the right approach,
but i want to know, if there is a way, i can build up a wrapper around the cake test, that will take the argument of the method name which i want to run?
There is no need to write a wrapper script
To run one test method
Use the filter option:
-> phpunit --help
PHPUnit 4.4.1 by Sebastian Bergmann.
Usage: phpunit [options] UnitTest [UnitTest.php]
phpunit [options] <directory>
...
Test Selection Options:
--filter <pattern> Filter which tests to run.
For example:
-> phpunit --debug --filter testValidationDefault tests/TestCase/Model/Table/PostsTableTest.php
PHPUnit 4.4.1 by Sebastian Bergmann.
Configuration read from /var/www/cakephp.dev/phpunit.xml.dist
Starting test 'App\Test\TestCase\Model\Table\PostsTableTest::testValidationDefault'.
I
Time: 130 ms, Memory: 9.75Mb
OK, but incomplete, skipped, or risky tests!
Tests: 1, Assertions: 0, Incomplete: 1.
www-data # dev [ /var/www/cakephp.dev ]
->
To run only one test use the filter option in the cake command line tool:
cake test app Model/Post --filter testGetAllPostsByAuthor
Works on CakePhp 2.2
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
Hi I am currently running through the ZF2 User Guide trying to run a PHPUnit Test on the skeleton application as outlined here http://zf2.readthedocs.org/en/latest/user-guide/unit-testing.html.
But even though I have not edited the Module and have copied all the files from the tutorial every time I run the PHPUnit Test in Zend Studio I get this error
Error:
Fatal error: Class 'ApplicationTest\Bootstrap' not found in C:\Program Files (x86)\Zend\Apache2\htdocs\exerciseDB\module\Application\test\ApplicationTest\Controller\IndexControllerTest.php on line 24
But when I click on the Bootstrap::getServiceManager(); on line 24 Zend Studio takes me to the correct method.
File Stucture:
module
|_Application
|_config
|_language
|_src
|_test
|_ApplicationTest
| |_Controller
| |_IndexControllerTest.php
|_Bootstrap.php
|_phpunit.xml.dist
|_TestConfig.php.dist
Can anyine tell me where I am going wrong?
This was a really annoying bug that is somewhat of an irritation. Your phpunit config seems to be changed slightly from the one on the skeleton application. To give you direct answer that fixed my issue I did the following...
module
|_Application
|_config
|_language
|_src
|_tests
|_ZendApplicationModule
| |_Framework
| |TestCase.php
| |_IndexControllerTest.php
| |_SampleTest.php
|_Bootstrap.php
|_phpunit.xml.dist
|_TestConfig.php.dist
With the base setup as outlined above from the skeleton APP I had to add
require_once 'Framework/TestCase.php';
To SampleTest.php
For your actual fix you will need to require_once the file that is generating the issue. That should fix it.
Also make sure to update your autoload_classmap.php
I ran into the same issue where phpunit was not seeing my "module/Application/test/phpunit.xml.dist" file (I had it miss-spelled)
Try adding the file directly to the command line:
phpunit --bootstrap Bootstrap.php .
I had the issue as well.
I solved it by running phpunit from the root of my ZF2 project with the following arguments:
./vendor/bin/phpunit
--bootstrap ./module/Rest/test/Bootstrap.php
One can also specify the Test suite to use:
./vendor/bin/phpunit
--bootstrap ./module/Rest/test/Bootstrap.php
./module/Rest/test/RestTest/Controller/RestControllerTest.php
more details here