---
title: Use Faker to generate random data for your tests
description: Learn how to use FakerJS to generate random data such as names, addresses
  and more which can be used in your tests.
source_url:
  html: https://testingbot.com/software-testing-questions/how-to-generate-fake-data
  md: https://testingbot.com/software-testing-questions/how-to-generate-fake-data.md
---

# Using Faker to generate Fake Data

- [![Share on Facebook](https://static.addtoany.com/buttons/facebook.svg) ](https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Ftestingbot.com%2Fsoftware-testing-questions%2Fhow-to-generate-fake-data.md&linkname= "Share on Facebook")
- [![Share on Twitter](https://static.addtoany.com/buttons/twitter.svg) ](https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Ftestingbot.com%2Fsoftware-testing-questions%2Fhow-to-generate-fake-data.md&linkname= "Share on Twitter")
- [![Share on LinkedIn](https://static.addtoany.com/buttons/linkedin.svg) ](https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Ftestingbot.com%2Fsoftware-testing-questions%2Fhow-to-generate-fake-data.md&linkname= "Share on LinkedIn")
- [![Share on HackerNews](https://static.addtoany.com/buttons/y18.svg) ](https://www.addtoany.com/add_to/hacker_news?linkurl=https%3A%2F%2Ftestingbot.com%2Fsoftware-testing-questions%2Fhow-to-generate-fake-data.md&linkname= "Share on HackerNews")

[Faker](https://fakerjs.dev/) is a NodeJS library that can be used to generate fake data.

It can be used to create dummy locations, names of people, avatars, products, sentences, phone numbers, dates and more.

To install FakerJS, simply use NPM:

```bash
npm install @faker-js/faker --save-dev
```

You can now generate fake data, such as this example:

```javascript
const { faker } = require('@faker-js/faker');
// or, if desiring a different locale
// const { fakerDE: faker } = require('@faker-js/faker');

const randomName = faker.person.fullName(); // Simon Coldwell
const randomEmail = faker.internet.email(); // stu.vermont@biznew.org
```

There's even support for multiple locales, so you can generate fake data in different languages.

FakerJS can easily be used with test frameworks such as Vitest and Jest, Playwright or Cypress.

For example, see this Playwright test code where we input a fake username and password in a form, using both FakerJS and Playwright.

```javascript
import { faker } from '@faker-js/faker/locale/en'
import { expect, test } from '@playwright/test'

test.describe('Testing the application', () => {
  test('should create an account with fake data', async ({
    page,
  }) => {
    const username = faker.internet.userName();
    const password = faker.internet.password();
    const email = faker.internet.exampleEmail();

    // Visit the webpage and create an account.
    await page.goto('https://www.example.com/register');
    await page.getByLabel('form_email').fill(email);
    await page.getByLabel('form_user').fill(username);
    await page.getByLabel('form_pass', { exact: true }).fill(password);
    await page.getByRole('button', { name: 'Register' }).click();
  });
});
```

- [![Share on Facebook](https://static.addtoany.com/buttons/facebook.svg) ](https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Ftestingbot.com%2Fsoftware-testing-questions%2Fhow-to-generate-fake-data.md&linkname=)
- [![Share on Twitter](https://static.addtoany.com/buttons/twitter.svg) ](https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Ftestingbot.com%2Fsoftware-testing-questions%2Fhow-to-generate-fake-data.md&linkname=)
- [![Share on Linkedin](https://static.addtoany.com/buttons/linkedin.svg) ](https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Ftestingbot.com%2Fsoftware-testing-questions%2Fhow-to-generate-fake-data.md&linkname=)
- [![Share on Hacker News](https://static.addtoany.com/buttons/y18.svg) ](https://www.addtoany.com/add_to/hacker_news?linkurl=https%3A%2F%2Ftestingbot.com%2Fsoftware-testing-questions%2Fhow-to-generate-fake-data.md&linkname=)

 ![TestingBot Logo](https://testingbot.com/assets/logo-head-2f7f08db4ac9c4a3b1a784047410f8a4ece708e7e9f10ed16e20fdd8310f8de3.svg)

## Sign up for a Free Trial

Start testing your apps with TestingBot.

No credit card required.

[Start Free Trial](https://testingbot.com/users/sign_up)

## Other Questions

### [What exactly is an iOS device?](https://testingbot.com/software-testing-questions/what-is-an-ios-device "What exactly is an iOS device?")

### [Change the timezone on a Mac machine](https://testingbot.com/software-testing-questions/how-to-change-your-time-zone-on-mac "Change the timezone on a Mac machine")

### [Learn about White Box Testing](https://testingbot.com/software-testing-questions/what-is-white-box-testing "Learn about White Box Testing")

### [Test on multiple browsers with Cypress](https://testingbot.com/software-testing-questions/how-to-test-cypress-on-different-browsers-and-devices "Test on multiple browsers with Cypress")

### [Check Android Screen Resolution](https://testingbot.com/software-testing-questions/how-to-check-screen-resolution-on-android "Check Android Screen Resolution")

### [Viewing the HTML source in Safari](https://testingbot.com/software-testing-questions/how-to-view-source-code-in-safari "Viewing the HTML source in Safari")
