Skip to content
...

Test Attribute

The plugin discovers tests by the #[Test()]#[Test()]Explicitly marks a method, function, or class as a test. attribute. This is the primary way to explicitly declare a method, function, or class as a test.

Plugin class: TestPlugin\Testo\Test\TestPlugin. Included in SuitePlugins\Testo\Application\Config\Plugin\SuitePlugins — enabled by default.

#[Test]

Explicitly marks a method, function, or class as a test.

#[Test()]

Can be used on classes, methods, and functions. When applied to a class (Test Case), all public methods with a void or never return type become tests. Otherwise, only the marked element becomes a test.

Examples:

php
// tests/Unit/Order.php
#[Test]
final class Order
{
    public function createsOrder(): void { /* ... */ }

    public function calculatesTotal(): void { /* ... */ }
}
php
// tests/Unit/Order.php
final class Order
{
    #[Test]
    public function createsOrder(): void { /* ... */ }

    #[Test]
    public function calculatesTotal(): void { /* ... */ }
}
php
// tests/Unit/order.php
#[Test]
function creates_order(): void { /* ... */ }

#[Test]
function calculates_total(): void { /* ... */ }

#[Test]
function applies_discount(): void { /* ... */ }