Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to enable code coverage in bitbucket piplines for my Laravel project.

Pavinthan August 2, 2018

How to enable code coverage in bitbucket piplines for my Laravel project.

Here my bitbucket-pipelines.yml


# This is a sample build configuration for PHP.
# Check our guides at https://confluence.atlassian.com/x/e8YWN for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: laratools/ci:7.2

options:
max-time: 30
pipelines:
branches:
master, dev:
- step:
caches:
- composer
script:
- composer install --no-progress --no-suggest
- export APP_ENV=testing
- cp .env.example .env
- php artisan key:generate
- vendor/bin/phpunit --log-junit ./test-reports/junit.xml

 

2 answers

1 vote
Pavinthan March 1, 2019

@Philip Hodder I'm sorry to this late response, yes I mean how much of my code testing in the build I need to add some rules depending that step in my pipeline

eg: code only move to production if coverage is 100% 

 

something like that

Philip Hodder
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 3, 2019

No worries for the delay.

We haven't scheduled any time to start looking into integrating Code Coverage directly into Pipelines. However, it sounds like you want to prevent a deployment from running based on the test coverage. In that case you could enforce that as part of your deploy step (or an earlier one).

For example:

pipelines:
branches:
master:
- step:
script:
- ./run-the-build
- ./run-the-tests
- ./verify-code-coverage # This would check for code coverage requirements, and fail the build if not met.
- ./deploy-to-production

Or if you wanted to enforce this on a PR:

pipelines:
branches:
feature/*:
- step:
name: Build and test
script:
- ./run-the-build
- ./run-the-tests
- ./verify-code-coverage # This would check for code coverage requirements, and fail the build if not met.
master:
- step:
name: Build and test
artifacts:
- binary-to-deploy
script:
- ./run-the-build
- ./run-the-tests
- step:
name: Deploy to production
deployment: production
script:
- ./deploy-to-production

If you're interested in built in support for code coverage tools, can you follow this feature request and provide more details of your use-case?

Thanks,

Phil

Like # people like this
0 votes
Philip Hodder
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 9, 2018

Hello,

Do you mean failed tests reporting, or test code coverage (which checks how many LoC are reached by all tests). From your phpunit command, it looks like the first.

If you mean failing test reporting. Have a look at the documentation here: https://confluence.atlassian.com/bitbucket/test-reporting-in-pipelines-939708543.html You should see some information in the 'Build teardown' that will include if the junit.xml file is found, and if it's parsed any failed tests. The UI will only show failed tests.

If you mean test code coverage, we currently don't support that. You'll need to output that to the logs or to an artifact to download: https://confluence.atlassian.com/bitbucket/using-artifacts-in-steps-935389074.html

Thanks,

Phil

kenkinder March 1, 2019

Hi Phil. Any chance code coverage could be integrated into bitbucket pipelines? It would be really helpful to review that as part of a pull request.

Like Barbara Ondrisek likes this
Philip Hodder
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 3, 2019

Hi Ken,

I agree it would be a useful feature to have. However, we currently have other features prioritised and haven't got Code Coverage on our immediate roadmap.

We have an open feature request for it here, which you can follow for updates: https://bitbucket.org/site/master/issues/15935/show-code-coverage-reports-for-jacoco Matt has posted a possible work around using the Build Status API (which some of our teams at Atlassian currently do).

Out of curiosity, which code coverage tools are you currently using? 

Thanks,

Phil

Luis Lobo July 26, 2020

@Philip Hodder In our case we are using node.js and using tools like nyc or c8 

They both support this reporters : https://github.com/istanbuljs/istanbuljs/tree/master/packages/istanbul-reports/lib

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events