innmind / black-box
Test library
5.10.0
2024-11-30 12:43 UTC
Requires
- php: ~8.2
- innmind/json: ^1.1
- phpunit/php-code-coverage: ~10.1|~11.0
- phpunit/php-timer: ~6.0|~7.0
- phpunit/phpunit: ~10.0|~11.0
- symfony/var-dumper: ~6.0|~7.0
Requires (Dev)
- innmind/coding-standard: ~2.0
- ramsey/uuid: ^4.1
- vimeo/psalm: ~5.6
- dev-develop
- 5.10.0
- 5.9.0
- 5.8.0
- 5.7.0
- 5.6.3
- 5.6.2
- 5.6.1
- 5.6.0
- 5.5.4
- 5.5.3
- 5.5.2
- 5.5.1
- 5.5.0
- 5.4.0
- 5.3.0
- 5.2.0
- 5.1.2
- 5.1.1
- 5.1.0
- 5.0.0
- 4.18.1
- 4.18.0
- 4.17.0
- 4.16.0
- 4.15.1
- 4.15.0
- 4.14.0
- 4.13.0
- 4.12.0
- 4.11.0
- 4.10.1
- 4.10.0
- 4.9.0
- 4.8.0
- 4.7.1
- 4.7.0
- 4.6.0
- 4.5.0
- 4.4.1
- 4.4.0
- 4.3.1
- 4.3.0
- 4.2.5
- 4.2.4
- 4.2.3
- 4.2.2
- 4.2.1
- 4.2.0
- 4.1.1
- 4.1.0
- 4.0.0
- 3.0.0
- 2.9.0
- 2.8.1
- 2.8.0
- 2.7.0
- 2.6.0
- 2.5.0
- 2.4.0
- 2.3.0
- 2.2.0
- 2.1.0
- 2.0.0
- 1.0.0
- dev-master
- dev-phpunit-11
- dev-github-action-printer
- dev-test-runner
This package is auto-updated.
Last update: 2024-11-30 12:44:48 UTC
README
BlackBox is a Property Based Testing framework and test runner.
Property Based Testing is a way to verify a piece of code always behave the same way (aka a Property) by testing it with multiple values of a given type.
The common introduction to this approach is the add
function that has 3 properties:
- it is commutative
- it is associative
- it is an identity function
To prove this via BlackBox you can do it this way:
use Innmind\BlackBox\{ Application, Set, Runner\Assert, }; Application::new([]) ->tryToProve(static function() { yield proof( 'add is commutative', given( Set\Integers::any(), Set\Integers::any(), ), static fn(Assert $assert, int $a, int $b) => $assert->same( add($a, $b), add($b, $a), ), ); yield proof( 'add is associative', given( Set\Integers::any(), Set\Integers::any(), Set\Integers::any(), ), static fn(Assert $assert, int $a, int $b, int $c) => $assert->same( add(add($a, $b), $c), add($a, add($b, $c)), ), ); yield proof( 'add is an identity function', given(Set\Integers::any()), static fn(Assert $assert, int $a) => $assert->same( $a, add($a, 0), ), ); }) ->exit();
By default BlackBox will generate 100 scenarii for each proof.
Note BlackBox use the term proof to emphasize that you are testing behaviours not specific scenarii, but these are NOT formal proofs
Installation
composer require --dev innmind/black-box
Documentation
Full documentation can be found in the here.