dave-liddament/test-splitter 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dave-liddament/test-splitter

最新稳定版本:0.4.0

Composer 安装命令:

composer create-project dave-liddament/test-splitter

包简介

Splits up PHPUnit tests so they can be ran in parallel (e.g. on GitHub actions)

README 文档

README

PHP versions: 8.1|8.2|8.3|8.4|8.5 Latest Stable Version License Total Downloads

Continuous Integration PHPStan max

Have you got a slow running PHPUnit test suite?

Do you want to split your tests over separate instances? If so, PHPUnit test case splitter might help. It splits tests into batches in a deterministic way. Each batch of tests can run in separate instances (e.g. by using a matrix in GitHub actions).

Usage

Install via Composer:

composer require --dev dave-liddament/test-splitter

This package provides an executable under vendor/bin/tsplit that takes two arguments: batch, and number of batches. It accepts a list of tests piped into stdin and outputs the tests for the specified batch to stdout.

To split the tests into 4 batches and run the first batch you can do:

vendor/bin/phpunit --filter `vendor/bin/phpunit --list-tests | vendor/bin/tsplit 1 4`

To run the second batch out of 4 you'd use:

vendor/bin/phpunit --filter `vendor/bin/phpunit --list-tests | vendor/bin/tsplit 2 4`

CI/CD Usage

GitHub Actions

Add this to your GitHub actions:

jobs:
  tests:
  
    strategy:
      fail-fast: false
      matrix: 
        test-batch: [1, 2, 3, 4]

    steps: 
      # Steps to checkout code, setup environment, etc.

      - name: "Tests batch ${{ matrix.test--batch }}"
        run: vendor/bin/phpunit --filter `vendor/bin/phpunit --list-tests | vendor/bin/tsplit ${{ matrix.test-batch }} 4`

This will split the tests over 4 different jobs.

GitLab CI/CD

test:
  stage: test
  parallel: 4
  script:
    - vendor/bin/phpunit --filter `vendor/bin/phpunit --list-tests | vendor/bin/tsplit ${CI_NODE_INDEX} ${CI_NODE_TOTAL}`

This will split the tests over 4 different jobs. GitLabs predefined variables CI_NODE_INDEX and CI_NODE_TOTAL are used to automatically specify the batch number and total number of batches.

Additional documentation

Alternative tools

Test splitter is a very simple tool. It was created in 2021, at the time no other tools did something similar. It solved a problem I had on a couple of client projects.

Since 2021 other tools that do similar things have been developed. If you want more mature or more feature rich tools then try these:

统计信息

  • 总下载量: 361.86k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 19
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 19
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-09-28