# `SeedFactory.Test`
[🔗](https://github.com/fuelen/seed_factory/blob/v0.10.1/lib/seed_factory/test.ex#L1)

Integrates `SeedFactory` with `ExUnit`.

## Usage

Add the following line to your test modules:
```elixir
use SeedFactory.Test, schema: MySeedFactorySchema
```

This will:
* initialize the schema via `SeedFactory.init/2` in a `setup_all` callback
* import `SeedFactory` functions:
  * `SeedFactory.exec/3`
  * `SeedFactory.produce/2`
  * `SeedFactory.rebind/3`
  * `SeedFactory.pre_exec/3`
  * `SeedFactory.pre_produce/2`
* import the `produce/1` macro (see below)

# `produce`
*macro* 

```elixir
@spec produce(
  SeedFactory.entity_name()
  | [
      SeedFactory.entity_name()
      | SeedFactory.rebinding_rule()
      | {SeedFactory.entity_name(), [SeedFactory.trait_request()]}
    ]
) :: Macro.t()
```

A macro for producing entities outside of `test` blocks.

Generates a `setup` callback that calls `SeedFactory.produce/2`, so the entities
are available in all tests within the scope. Accepts the same arguments as `produce/2`. This:

    produce [:company, user: [:active, :admin]]

is equivalent to:

    setup context do
      produce(context, [:company, user: [:active, :admin]])
    end

Can only be called outside of `test` blocks. For producing entities inside a test,
use `SeedFactory.produce/2` directly.

## Examples

```elixir
produce :company

test "my test", %{company: company} do
  assert my_function(company)
end
```

```elixir
produce [:company, user: [:active, :admin, as: :active_admin]]

test "my test", %{company: company, active_admin: admin} do
  assert my_function(company, admin)
end
```

```elixir
produce org: :org1
produce org: :org2

test "my test", %{org1: org1, org2: org2} do
  assert my_function(org2, org1)
end
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
