Faker is a pure Elixir library for generating fake data.
- add
{:faker, "~> 0.9"}to your deps inmix.exs; - add
:fakerto list of your applications; - jump to usage examples.
Example mix.exs:
...
def application do
[applications: [:logger, :faker]]
end
...
defp deps do
[{:faker, "~> 0.9"}]
end
...In your mix.exs file, add the :faker project to your dependencies
(optionally include the version):
defp deps do
[{:faker, "~> 0.9", only: :test}]
endDo a mix deps.get to fetch the dependency. That's it.
If you want to use faker outside tests remove , only: :test part.
- OTP18+
- Elixir 1.3+
You need to start :faker application, but due to the many usages of fake data,
(seed database, tests, etc) there's no right place to do it. For example, if you
want to use it in tests, just add Faker.start to test/test_helper.exs, then,
use any function described in the documentation or
in usage examples.
- If you get a message like the one below when you call
Faker.Address.city, you need to add:fakerto your application's mix file, in theapplicationsfunction, 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/0Faker was designed as a lightweight library, that's why it can be easily used with other tools.
You can build templates for testing purposes with the Blacksmith project. See the Blacksmith readme for details.
Released under the MIT License.