Disabling Tests

Sometimes you might need to disable a test for a variety of reasons. With AsyncUnit you can disable your tests, TestCases, and TestSuites with the Disabled Attribute!

In a complex test suite there might be times where you need to disable tests for a variety of reasons. If you're familiar with PHPUnit their nomenclature is skipped or ignored. In AsyncUnit we consolidate this into one concept; a disabled test. You can disable not only a test but an entire TestCase or even a whole TestSuite with the #[Disabled] attribute!

Conditional test disabling is a feature that is coming in the 0.6 version!

Disabling a single test

If you just need to disable a single test simple annotate that method with the #[Disabled] Attribute!

<?php
use Cspray\Labrador\AsyncUnit\TestCase;
use Cspray\Labrador\AsyncUnit\Attribute\Test;
use Cspray\Labrador\AsyncUnit\Attribute\Disabled;
class MyDisabledTest extends TestCase {
#[Test]
#[Disabled]
public function checkSomething() {
// none of this matters because this is never executed
}
}

When disabling a single test any #[BeforeEach] or #[AfterEach] hook defined on the TestCase will not be executed.

Disabling a TestCase

Chances are if one test in a TestCase needs to be disabled so do all the other tests. In those situations you can simply annotate the class with the #[Disabled] Attribute.

<?php
use Cspray\Labrador\AsyncUnit\TestCase;
use Cspray\Labrador\AsyncUnit\Attribute\Test;
use Cspray\Labrador\AsyncUnit\Attribute\Disabled;
#[Disabled]
class MyDisabledTestCase extends TestCase {
#[Test]
public function checkSomething() {
// none of this matters because this is never executed
}
#[Test]
public function checkSomethingElse() {
// this doesn't matter either... it will never run!
}
#[Test]
public function anotherDisabledTest() {
// more stuff that won't ever run
}
}

When disabling an entire TestCase not only are none of the tests executed but none of the hooks associated with that TestCase are executed either.

Disabling a TestSuite

If you're utilizing an explicit TestSuite it might be beneficial to disable all of the TestCase associated to the TestSuite. Just like with the TestCase simply annotate the appropriate class with the #[Disabled] Attribute!

<?php
use Cspray\Labrador\AsyncUnit\TestCase;
use Cspray\Labrador\AsyncUnit\TestSuite;
use Cspray\Labrador\AsyncUnit\Attribute\Test;
use Cspray\Labrador\AsyncUnit\Attribute\DefaultTestSuite;
use Cspray\Labrador\AsyncUnit\Attribute\Disabled;
#[Disabled]
#[DefaultTestSuite]
class MyTestSuite extends TestSuite {}
class FirstTestCase extends TestCase {
#[Test]
public function checkSomething() {
// none of this matters because this is never executed
}
#[Test]
public function checkSomethingElse() {
// this doesn't matter either... it will never run!
}
#[Test]
public function anotherDisabledTest() {
// more stuff that won't ever run
}
}
class SecondTestCase extends TestCase {
#[Test]
public function checkSomething() {
// none of this matters because this is never executed
}
#[Test]
public function checkSomethingElse() {
// this doesn't matter either... it will never run!
}
#[Test]
public function anotherDisabledTest() {
// more stuff that won't ever run
}
}

When disabling a TestSuite no tests or hooks for the TestSuite or any of its TestCase will be invoked!