Generate Realistic Test Data in Go with the GoFakeIt Library

This article introduces GoFakeIt, a lightweight Go library for quickly generating diverse fake data—personal, address, financial, network, and more—explains its key features, shows how to install it via go get, and provides practical code examples for each data type.

FunTester
FunTester
FunTester
Generate Realistic Test Data in Go with the GoFakeIt Library

Why Use Fake Data?

During software development and testing, large amounts of realistic data are often required, but using real data can raise privacy and security concerns. Generating synthetic data with GoFakeIt helps developers avoid these risks while speeding up development, testing, and demo workflows.

Key Features of GoFakeIt

Supports many data types such as names, addresses, phone numbers, emails, IPs, UUIDs, dates, and custom text.

Simple, intuitive API that requires only a single function call to produce data.

Highly random data with optional seed control for reproducible results.

Customizable generation logic via regular expressions or templates.

Localization support for different languages and regions.

Lightweight and performant, suitable for high‑throughput scenarios.

Installation

Install the library with the standard go get command:

go get github.com/brianvoe/gofakeit/v6

Personal Information Example

The following program generates a random full name, first name, last name, email, and phone number.

package main

import (
    "fmt"
    "github.com/brianvoe/gofakeit/v6"
)

func main() {
    gofakeit.Seed(0)
    fmt.Println("Full Name:", gofakeit.Name())
    fmt.Println("First Name:", gofakeit.FirstName())
    fmt.Println("Last Name:", gofakeit.LastName())
    fmt.Println("Email:", gofakeit.Email())
    fmt.Println("Phone Number:", gofakeit.Phone())
}

Sample output:

Full Name: Lucious Heller
First Name: Toni
Last Name: Mayer
Email: [email protected]
Phone Number: 8425416172

Address Information Example

This snippet shows how to generate a full address, street, city, state, and ZIP code.

package main

import (
    "fmt"
    "github.com/brianvoe/gofakeit/v6"
)

func main() {
    gofakeit.Seed(0)
    addr := gofakeit.Address()
    fmt.Println("Full Address:", addr.Address)
    fmt.Println("Street:", gofakeit.Street())
    fmt.Println("City:", gofakeit.City())
    fmt.Println("State:", gofakeit.State())
    fmt.Println("Zip Code:", gofakeit.Zip())
}

Sample output:

Full Address: 638 Lake Estatesstad, El Paso, Massachusetts 39037
Street: 9103 Hillsmouth
City: Portland
State: Arizona
Zip Code: 51991

Financial Data Example

Generate random credit‑card details, currency information, and a price.

package main

import (
    "fmt"
    "github.com/brianvoe/gofakeit/v6"
)

func main() {
    gofakeit.Seed(0)
    cc := gofakeit.CreditCard()
    fmt.Printf("Credit Card Info:
  Type: %s
  Number: %s
  Expiry: %s
  CVV: %s
", cc.Type, cc.Number, cc.Expiry, cc.Cvv)
    cur := gofakeit.Currency()
    fmt.Printf("Currency:
  Code: %s
  Symbol: %s
", cur.Short, cur.Symbol)
    price := gofakeit.Price(10, 1000)
    fmt.Printf("Price: $%.2f
", price)
}

Sample output:

Credit Card Info:
  Type: Hipercard
  Number: 6440047269018720498
  Expiry: 08/27
  CVV: 865
Currency:
  Code: NAD
  Symbol: Namibia Dollar
Price: $500.50

Network Data Example

Generate a domain name, URL, and IPv4 address.

package main

import (
    "fmt"
    "github.com/brianvoe/gofakeit/v6"
)

func main() {
    gofakeit.Seed(0)
    fmt.Println("Domain Name:", gofakeit.DomainName())
    fmt.Println("URL:", gofakeit.URL())
    fmt.Println("IPv4 Address:", gofakeit.IPv4Address())
}

Sample output:

Domain Name: corporategenerate.info
URL: https://www.leadend-to-end.net/generate/expedite/extend
IPv4 Address: 85.57.205.65

Date and Time Example

Generate random dates, times, and combined datetime strings.

package main

import (
    "fmt"
    "github.com/brianvoe/gofakeit/v6"
)

func main() {
    gofakeit.Seed(0)
    d := gofakeit.Date()
    fmt.Println("Random Date:", d.Format("2006-01-02 15:04:05"))
    fmt.Println("Random Time:", d.Format("15:04:05"))
    fmt.Println("Random DateTime:", d.Format("2006-01-02 15:04:05"))
}

Sample output:

Random Date: 2020-12-07 00:06:15
Random Time: 00:06:15
Random DateTime: 2020-12-07 00:06:15

Text and File Example

Generate Lorem Ipsum sentences, random sentences, and paragraphs.

package main

import (
    "fmt"
    "github.com/brianvoe/gofakeit/v6"
)

func main() {
    gofakeit.Seed(0)
    fmt.Println("Lorem Ipsum:", gofakeit.LoremIpsumSentence(5))
    fmt.Println("Random Sentence:", gofakeit.Sentence(10))
    fmt.Println("Random Paragraph:", gofakeit.Paragraph(3, 5, 10, "."))
}

Sample output (truncated for brevity):

Lorem Ipsum: Velit voluptas ex et in.
Random Sentence: Problem however later group annually by in damage college simply.
Random Paragraph: That e.g. whose aha parrot could occasionally unless hmm huh. ...

Other Data Types

Additional generators include UUID, boolean, numeric ranges, and hex color codes.

package main

import (
    "fmt"
    "github.com/brianvoe/gofakeit/v6"
)

func main() {
    gofakeit.Seed(0)
    fmt.Println("Random UUID:", gofakeit.UUID())
    fmt.Println("Random Boolean:", gofakeit.Bool())
    fmt.Println("Random Number:", gofakeit.Number(1, 100))
    fmt.Println("Random Hex Color:", gofakeit.HexColor())
}

Sample output:

Random UUID: d73b42b0-5ba7-48f1-a3f0-3738d458261d
Random Boolean: false
Random Number: 30
Random Hex Color: #72a72e

Conclusion

GoFakeIt is a powerful and flexible Go library that enables developers to generate a wide variety of fake data quickly and reliably. Its straightforward API and extensive data type support make it ideal for simulating realistic scenarios in development, testing, and demonstrations while avoiding the pitfalls of using real production data.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendData GenerationtestingGolangGoFake DataGoFakeIt
FunTester
Written by

FunTester

10k followers, 1k articles | completely useless

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.