Skip to content

Commit c7d34ce

Browse files
author
Daniel O'Connell
committed
Document the @example annotation for Unit tests
1 parent 28b87a8 commit c7d34ce

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

docs/07-AdvancedUsage.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,32 @@ class EndpointCest
265265

266266
```
267267

268+
## Example Annotation
269+
270+
As well as the ``\Codeception\Example` attribute, available for Cest tests, the `@example` attribute allows you to
271+
inject test parameters in place of an actual [DataProvider](#dataprovider-attribute) for Unit tests.
272+
273+
```php
274+
<?php
275+
namespace Tests\Unit;
276+
277+
class ExampleTest extends \Codeception\Test\Unit
278+
{
279+
/**
280+
* @param mixed $value
281+
* @example [3.14159]
282+
* @example ["a string"]
283+
* @example [["this", "is", "an", "array"]]
284+
* @example [{"associative": "array"}]
285+
*/
286+
public function testExample($value)
287+
{
288+
$this->assertNotEmpty($value, "Expected a value");
289+
}
290+
}
291+
```
292+
> `@testWith`: as of [Codeception 5.0](https://github.com/Codeception/Codeception/pull/6491), PHPUnit's `@testWith` is no longer supported. `@example` is a good, almost drop-in, replacement.
293+
268294
## DataProvider Attribute
269295

270296
You can also use the `@dataProvider` annotation for creating dynamic examples for [Cest classes](#Cest-Classes), using a **protected method** for providing example data:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy