How to add multiple codeception suites to different folders in one project? - php

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

Related

Run suites of included files in codeception

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

SonarCloud branch has no lines of code - bitbucket pipelines - sonarsource/sonarcloud-scan

I am trying to integrate sonarcloud with Bitbucket pipeline. I have a simple test project with single file named index.php consisting few lines.
I am exactly not sure what method should I follow.
I have created sonar-project.properties files that consists following lines.
sonar.sourceEncoding=UTF-8
sonar.host.url=https://sonarcloud.io/dashboard?id=first_ftp
sonar.projectKey=first_ftp
Here is my yml file
image: aariacarterweir/lamp-gitftp:latest
clone:
depth: full # SonarCloud scanner needs the full history to assign issues properly
definitions:
caches:
sonar: ~/.sonar/cache # Caching SonarCloud artifacts will speed up your build
steps:
- step: &build-test-sonarcloud
name: Build, test and analyze on SonarCloud
caches:
- node
- sonar
script:
- npm install --quiet
- npm run test -- --code-coverage --no-watch --no-progress --browsers=ChromeHeadlessNoSandbox
- pipe: sonarsource/sonarcloud-scan:0.1.5
variables:
SONAR_TOKEN: ${SONAR_TOKEN}
EXTRA_ARGS: '-Dsonar.sources=src -Dsonar.tests=src -Dsonar.test.inclusions="**/testing/**,**/*.spec.ts" -Dsonar.typescript.lcov.reportPaths=coverage/lcov.info'
When I check into sonarcloud website, It tells
The main branch has no lines of code
Can anybody help me how to configure properly sonarcloud with bitbucket for php project.
I've had the same issue - in my case it was because of the name of the project - it was called ---------Test, and apparently, by default, Sonar will treat that as a test assembly and will exclude it from analysis.
Before running code analysis in bitbucket pipelines, you would have to first manually run analysis(only once). By following below steps.

how to run codeception tests and Symfony tests

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.

How can i debug a failed ci build?

i created some tests with PHPUnit and laravel. The tests are running locally successful, but as a gitlab ci job there is an error.
Here is the ci log:
There was 1 failure:
1) Tests\Feature\AuthTest::testAuthLoggedInIsAdmin
Expected status code 200 but received 500.
Failed asserting that false is true.
/builds/XXX/webproject/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:55
/builds/XX/webproject/tests/Feature/AuthTest.php:53
For the better debug and finding a solution i need the error trace from the project or the error.log from the webserver.
What is the best practise to debug errors in the ci?
ok, the solution is very simple... i don't delete the question. Here is the solution:
You have to add an artifact to the job. You can set the artifact, that only on failures the artifact is created. If there is an failure on the build, the hole project is dumped to a seperated location. Now you can browse each files on the dump.
.gitlab-ci.yml
stages:
- test
- deploy
php-7.0:
stage: test
type: test
services:
- mysql:latest
image: tetraweb/php:7.0
script:
- bash .gitlab-ci.sh
- php vendor/bin/phpunit --coverage-text --colors=never
artifacts:
when: on_failure
name: "${CI_BUILD_STAGE}_${CI_BUILD_REF_NAME}_FAILED"
paths:
- "."
untracked: false
expire_in: 1 day
deploy:
stage: deploy
# etc...
Here are more informations about artifacts.
You can download the artifacts in the pipelines section in gitlab:

Using Codeception to run existing Laravel 5.1 PHPUnit tests

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.

Categories