Mohammad.Kaab
Mohammad.Kaab

Reputation: 1105

How to run specific tests at each pull-request?

Let's assume that we have more than 1500 tests, and before of pull-request get merged to master branch we have a test pipeline that always runs the tests, and it takes more than 45min for all of the tests to get run. Some of these tests are not necessary to run again and again and again and some of them should run.

Do we have a solution to specify which tests should be run in which pull-request and which test shouldn't run in a specific pull-request or I should ask it like this. Can we somehow define a filter to specify which tests should get run in [X]pull-request?

Upvotes: 4

Views: 930

Answers (1)

Alexander Zhukov
Alexander Zhukov

Reputation: 4557

You should be able to configure phpunit to run specific tests for a particular branch, for example, in the configuration below, phpunit will run all tests for the master branch, and run only a subset of tests for any branch that matches the feature/* glob pattern:

pipelines:
  default:
    - step:
        name: Run all tests
        script:
          - phpunit mydir
  branches:
    master:
      - step:
          name: Run all tests
          script:
            - phpunit mydir
    'feature/*':
      - step:
          name: Run only MyTest test class
          script:
            - phpunit --filter MyTest

Alternatively, you should be able decide which test to run based on the BITBUCKET_BRANCH environment variable:

pipelines:
  default:
    - step:
        name: Run test that match the name of the branch
        script:
          - phpunit --filter "${BITBUCKET_BRANCH}"

Upvotes: 1

Related Questions