> For the complete documentation index, see [llms.txt](https://docs.labrador-kennel.io/async-unit/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.labrador-kennel.io/async-unit/tutorials/data-providers.md).

# Data Providers

When a test needs to make the same assertion across a variety of data a *data provider* can reduce the amount of duplication necessary to write the appropriate tests. A data provider is a public method on the `TestCase` that returns an array of arrays with the appropriate arguments for the test. The test needing to use the data provider should be annotated with the `#[DataProvider]` Attribute and define parameters on its method signature.

```php
<?php

use Cspray\Labrador\AsyncUnit\TestCase;
use Cspray\Labrador\AsyncUnit\Attribute\Test;
use Cspray\Labrador\AsyncUnit\Attribute\DataProvider;

class MyDataProviderTestCase extends TestCase {

    public function myData() : array {
        return [
            ['async unit', 'phpunit'],
            ['AsyncUnit', 'AsyncUnit'],
            ['AsyncUnit', 'async unit']
        ];
    }

    #[Test]
    #[DataProvider('myData')]
    public function checkStringsAreEqual(string $expected, string $actual) : void {
        $this->assert()->stringEquals($expected, $actual);
    }

}
```

Each set of arguments will have its own `TestCase` instance and will have all of the appropriate test hooks invoked.
