Giter VIP home page Giter VIP logo

codeception-timekeeper's Introduction

Codeception TimeKeeper

A Codeception extension & Robo task that records test runtimes and lets you split tests into equal runtime-based groups for parallel runs.

This can be hugely useful when running your tests in an automated fashion, such as in a Continuous Integration system. You can schedule multiple parallel test runs, each with roughly-equal runtimes.

This extension supports the following Codeception version:

  • 3.x
  • 4.x

Usage

First, install this package:

composer require chinthakagodawita/codeception-timekeeper

Codeception time reporting extension

Update your codeception.yml with:

extensions:
    enabled:
        - ChinthakaGodawita\CodeceptionTimekeeper\Reporter:
              report_location: _data/time_report.json

Then run your tests, a report with runtimes for each test will be output to _data/time_report.json. This isn't much use on its own, read on for how you can use this to run your tests in parallel.

Parallel test runs via Robo

Install Robo:

composer require --dev consolidation/robo

Update your Robofile:

<?php

class RoboFile extends \Robo\Tasks {

    use \ChinthakaGodawita\CodeceptionTimekeeper\SplitsTestsByTime;

    public function taskSplitTests(): \Robo\Result
    {
        $groups = 3;
        $timeReportLocation = '_data/time_report.json';
        return $this->taskSplitTestsByTime($groups, $timeReportLocation)
          ->projectRoot('.')
          ->testsFrom('tests')
          ->groupsTo('tests/_data/timekeeper/group_')
          ->run();
    }

}

Then update your codeception.yml file with:

groups:
  timekeeper_*: tests/_data/timekeeper/group_*

This tells Codeception about the existence of the test groups we've just created.

You'll be able to split tests using:

php vendor/bin/robo split:tests

And run these test groups using:

php vendor/bin/codecept run -g timekeeper_0
php vendor/bin/codecept run -g timekeeper_1
php vendor/bin/codecept run -g timekeeper_2
# etc.

See the Codeception documentation for more information.

Troubleshooting

Some of my tests depend on each other

This extension does not currently support tests with dependencies. Support for this is coming soon.

Help! I'm seeing strange PHP compatibility errors

If you're seeing errors similar to any of the below, then you've hit a variation of codeception/codeception#5031

  • ERROR: Declaration of Codeception\Test\Test::run(?PHPUnit\Framework\TestResult $result = NULL) must be compatible with PHPUnit\Framework\Test::run(?PHPUnit\Framework\TestResult $result = NULL): PHPUnit\Framework\TestResult
  • ERROR: Declaration of Codeception\Test\Test::toString() must be compatible with PHPUnit\Framework\SelfDescribing::toString(): string

The simplest way to fix this, till a real fix lands upstream, is to add the following to the very top of your Robofile instead of just relying on Composer's autoloader:

<?php

require_once 'vendor/autoload.php';
require_once 'vendor/codeception/codeception/autoload.php';

Update these paths depending on where your Robofile lives in relation to Composer's vendor directory.

This forces Codeception's autoloader to fire and redeclare the PHPUnit classes that it needs to function.

Inspiration

codeception-timekeeper's People

Contributors

chinthakagodawita avatar

Watchers

 avatar  avatar  avatar

codeception-timekeeper's Issues

Add tests

Test for the following variations:

PHP:

  • 7.2
  • 7.3
  • 7.4
  • 8.0 (RC?)

Codeception:

  • 3.x
  • 4.x

Add test dependency support

i.e. if testA @dependsOn testB then they should be executed sequentially in the same test group rather than in separate groups (which could happen at the moment).

Add report merge support

When running parallel groups, each group will output its own time report. We need someway of merging all of these reports together for use in subsequent tests

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.