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

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

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

dave-liddament/test-splitter

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:

dave-liddament/test-splitter 适用场景与选型建议

dave-liddament/test-splitter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 534.81k 次下载、GitHub Stars 达 20, 最近一次更新时间为 2021 年 09 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 dave-liddament/test-splitter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 dave-liddament/test-splitter 我们能提供哪些服务?
定制开发 / 二次开发

基于 dave-liddament/test-splitter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 534.81k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 20
  • 点击次数: 27
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

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