Skip to content

QuotaSignal/faker

 
 

Repository files navigation

Faker

build Version Hex Docs License Issues Downloads Gitter Last Updated

Faker is a pure Elixir library for generating fake data.

Quickstart

  • add {:faker, "~> 0.19.0-alpha.1"} to your deps in mix.exs:

    defp deps do
      [
        {:faker, "~> 0.19.0-alpha.1", only: :test}
      ]
    end
  • run:

    mix deps.get
    
  • add Faker.start() to test/test_helper.exs:

    ExUnit.start()
    Faker.start()
  • jump to usage examples.

Requirements

  • OTP 19+
  • Elixir 1.6+

Usage

See documentation and usage examples.

Deterministic Testing

Faker can produce deterministic output tied to ExUnit's seed, making test failures reproducible by re-running with the same --seed value.

Add the following to test/test_helper.exs:

:ets.new(:seed_registry, [:named_table, :public])
Application.put_env(:faker, :random_module, Faker.Random.Test)
ExUnit.start()

That's it. Faker will automatically pick up ExUnit's seed. Running mix test --seed 12345 will produce the same Faker values every time, and ExUnit always prints its seed (Randomized with seed 12345) so you can reproduce any test run by re-using that seed.

To override the seed for a specific test, use Faker.Random.Test.seed/1:

setup do
  Faker.Random.Test.seed(42)
  :ok
end

Troubleshooting

  • If you get a message like the one below when you call Faker.Address.city/0, you need to add :faker to your application's mix file, in the applications function, as above.

    ** (FunctionClauseError) no function clause matching in Faker.Address.city_count/1
    lib/faker/address.ex:48: Faker.Address.city_count(nil)
    lib/faker/address.ex:41: Faker.Address.city/0
    

Tools

Faker was designed as a lightweight library, that's why it can be easily used with other tools.

Templating

You can build templates for testing purposes with the Blacksmith project. See the Blacksmith readme for details.

Team

Faker was originally written by Igor Kapkov.

Current list of maintainers:

Contributing

Do you want to become a maintainer?

See our CONTRIBUTING.md and start contributing today. We usually elect new maintainers based on contributions.

Thanks

Sponsored by Evil Martians

Released under the MIT License.

About

Faker is a pure Elixir library for generating fake data.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Elixir 100.0%