You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By default, if no configuration file is provided, Testo will run tests from the `tests` folder.
26
26
27
-
To customize the configuration, create a `testo.php` file in the root of your project:
27
+
To configure Testo, create a `testo.php` file in the root of your project:
28
28
29
29
```php
30
30
<?php
@@ -39,19 +39,11 @@ return new ApplicationConfig(
39
39
suites: [
40
40
new SuiteConfig(
41
41
name: 'Unit',
42
-
location: new FinderConfig(
43
-
include: ['tests/Unit'],
44
-
),
42
+
location: ['tests/Unit'],
45
43
),
46
44
new SuiteConfig(
47
45
name: 'Sources',
48
-
location: new FinderConfig(
49
-
include: ['src'],
50
-
),
51
-
plugins: SuitePlugins::only(
52
-
new InlineTestPlugin(),
53
-
new BenchmarkPlugin(),
54
-
),
46
+
location: ['src'],
55
47
),
56
48
],
57
49
);
@@ -63,54 +55,49 @@ To learn more about configuration, visit the [Configuration](configuration.md) s
63
55
64
56
## Writing Your First Test
65
57
66
-
Create a test class in the configured test directory (e.g., `tests/Unit/CalculatorTest.php`):
58
+
Create a test class in the configured directory (e.g., `tests/Unit/MyFirstTest.php`) and add a method with the `#[Test]` attribute:
67
59
68
60
```php
69
-
<?php
70
-
71
-
declare(strict_types=1);
72
-
73
-
namespace Tests\Unit;
74
-
75
-
use Testo\Assert;
76
-
use Testo\Assert\ExpectException;
77
-
use Testo\Application\Attribute\Test;
78
-
use Testo\Retry\RetryPolicy;
79
-
80
-
final class CalculatorTest
61
+
final class MyFirstTest
81
62
{
82
63
#[Test]
83
64
public function dividesNumbers(): void
84
65
{
85
66
$result = 10 / 2;
86
67
87
-
Assert::same(5.0, $result);
88
-
Assert::notSame(5, $result); // Types matter!
68
+
Assert::same($result, 5.0);
69
+
Assert::notSame($result, 5); // Types matter
89
70
}
71
+
}
72
+
```
90
73
91
-
#[Test]
92
-
#[RetryPolicy(maxAttempts: 3)] // Retries up to 3 times if test fails
93
-
public function flakyApiCall(): void
94
-
{
95
-
$response = $this->makeExternalApiCall();
74
+
The `#[Test]` attribute marks the method as a test, and the `Assert` facade checks assertions.
75
+
Testo supports a wide range of assertions via `Assert` and expectations via `Expect`.
96
76
97
-
Assert::same(200, $response->status);
77
+
Use attributes to extend test functionality.
78
+
For example, `#[Retry]` retries a test on failure, and `#[ExpectException]` expects a specific exception:
79
+
80
+
```php
81
+
#[Test]
82
+
final class MyFirstTest
83
+
{
84
+
#[Retry(maxAttempts: 5)] // Retries up to 5 times if test fails
85
+
public function flakyTest(): void
86
+
{
87
+
Assert::same(mt_rand(0, 2), 2);
98
88
}
99
89
100
-
#[Test]
101
90
#[ExpectException(\RuntimeException::class)]
102
-
public function throwsException(): void
91
+
public function throwsException(): never
103
92
{
104
93
throw new \RuntimeException('Expected error');
105
94
}
106
95
}
107
96
```
108
97
109
-
### Key Points
110
-
111
-
- The `#[Test]` attribute marks test methods, and test classes don't need to inherit from a base class. See [Writing Tests](./writing-tests) for more options.
112
-
- Use the `Assert` facade for assertions and `Expect` for expectations.
113
-
- Testo provides multiple attributes to extend testing capabilities (retry policies, exception handling, and more).
98
+
::: question Why `#[Test]` on a class?
99
+
You can put `#[Test]` on a class — then all public methods with return type `void` or `never` become tests.
0 commit comments