Skip to content

Commit 97643f0

Browse files
committed
docs(README): Add section on running tests and writing test examples
1 parent 00956f6 commit 97643f0

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,66 @@ return new ApplicationConfig(
5656
);
5757
```
5858

59+
### Running Tests
60+
61+
To run your tests, execute:
62+
63+
```bash
64+
vendor/bin/testo
65+
```
66+
67+
### Writing Your First Test
68+
69+
Create a test class in the configured test directory (e.g., `tests/CalculatorTest.php`):
70+
71+
```php
72+
<?php
73+
74+
declare(strict_types=1);
75+
76+
namespace Tests;
77+
78+
use Testo\Assert;
79+
use Testo\Attribute\Test;
80+
use Testo\Attribute\RetryPolicy;
81+
use Testo\Attribute\ExpectException;
82+
83+
final class CalculatorTest
84+
{
85+
#[Test]
86+
public function dividesNumbers(): void
87+
{
88+
$result = 10 / 2;
89+
90+
Assert::same(5.0, $result);
91+
Assert::notSame(5, $result); // Types matter!
92+
}
93+
94+
#[Test]
95+
#[RetryPolicy(maxAttempts: 3)]
96+
public function flakyApiCall(): void
97+
{
98+
// Retries up to 3 times if test fails
99+
$response = $this->makeExternalApiCall();
100+
101+
Assert::same(200, $response->status);
102+
}
103+
104+
#[Test]
105+
#[ExpectException(\RuntimeException::class)]
106+
public function throwsException(): void
107+
{
108+
throw new \RuntimeException('Expected error');
109+
}
110+
}
111+
```
112+
113+
What to note:
114+
- Use the `#[Test]` attribute to mark test methods
115+
- Test classes don't need to extend any base class
116+
- Use `Assert` class for assertions (`same`, `true`, `false`, `null`, `contains`, `instanceOf`, etc.)
117+
- Testo provides multiple attributes to extend testing capabilities (retry policies, exception handling, and more)
118+
59119
## IDE Support
60120

61121
Testo comes with the [IDEA plugin `Testo`](https://plugins.jetbrains.com/plugin/28842-testo?noRedirect=true).

0 commit comments

Comments
 (0)