kotlin-faker

repository·master·Indexed 19 days ago

https://github.com/serpro69/kotlin-faker

A comprehensive fake data generation library for the JVM, ported from the Ruby faker gem. It enables the generation of realistic data for testing, development, and data anonymization across Kotlin, Java, Android, and Scala projects. The library includes a Bill-of-Materials (BOM) for dependency management, a CLI tool called faker-bot for exploring providers, and various extensions for domains like books, commerce, and Kotest property testing.

Tokens
86.7K
Snippets
379
Records
413
Agent score
64%

What's inside kotlin-faker

  1. Overview of kotlin-faker capabilities

    master

    kotlin-faker is a library designed to generate realistic-looking fake data for development, testing, and data anonymization purposes. It provides data generators across various domains including:

    • Names
    • Addresses
    • Internet
    • Banking
    • Books
    • Movies and TV
    • ...and many more.

    Key features include support for over 60 locales, unique data generation (both within a domain and within a specific function), a CLI application for looking up generator functionality, and advanced capabilities like random class instance generation, string templating, and generation of random numbers, strings, enums, and UUIDs.

  2. Overview of :faker modules

    master

    The :faker modules provide additional domain-specific data providers that extend the core kotlin-faker functionality. These modules are used to generate specialized fake data that falls outside the scope of the core library.

    Available domain modules include:

    • books
    • commerce
    • creatures
    • databases
    • edu
    • games
    • humor
    • japmedia
    • lorem
    • misc
    • movies
    • music
    • sports
    • tech
    • travel
    • tvshows
  3. Use `:extension` modules for third-party libraries

    master

    The :extension modules provide specialized integrations for popular third-party testing libraries.

    One available extension is kotest-property, which allows you to use kotlin-faker functionality within Kotest Arb generators. This enables seamless integration between kotlin-faker and Kotest property-based testing.

    Important: Extension modules require the main kotlin-faker dependency to be present on your classpath unless the specific extension's documentation states otherwise.

  4. About kotlin-faker

    master

    kotlin-faker is a comprehensive data-generation library for the JVM, designed for development, testing, and data anonymization. It is a Kotlin port of the popular Ruby faker gem. It supports Kotlin, Java, Android, Scala, and other JVM-based projects.

    Key domains include:

    • Names
    • Addresses
    • Internet
    • Banking
    • Books
    • Games
    • And many more.
  5. Compare kotlin-faker with other JVM Faker libraries

    master

    When choosing a data generation library for the JVM, kotlin-faker is positioned as a Kotlin-first alternative to several Java-based libraries. Key differentiators include:

    • Kotlin DSL Support: kotlin-faker provides a native Kotlin DSL, whereas most other libraries (like datafaker or java-faker) are Java-centric.
    • CLI App: kotlin-faker includes a built-in CLI application.
    • Provider & Locale Count: It offers a high number of providers (213) and locales (60).
    • Unique Values: Supports unique value generation.
    • Maintenance: It is actively maintained compared to some older alternatives like java-faker or jfairy.

    Performance Benchmark Context

    Benchmarks were conducted by creating a new Faker instance and generating 1,000,000 full names. On the tested hardware (Intel i9-8950HK, 32GB RAM), kotlin-faker (v1.11.0) performed at approximately 2890ms, performing similarly to datafaker (v1.4.0) and significantly faster than java-faker (v1.0.2) or jfairy (v0.6.5).

    fun main() {
        List(10) { it }.sumOf {
            measureTimeMillis {
                val f = Faker()
                repeat(1_000_000) { f.name.name() }
            }
        } / 10
    }
  6. Explore available Data Generators (Fakers)

    master

    Kotlin-Faker provides various specialized data generators, referred to as 'Fakers', organized by domain. These generators correspond to YAML dictionary files used to produce randomized data.

    Note: While many domains are available, not all providers or their specific functions are implemented in every version. To see the full list of available methods for a specific domain, consult the dedicated documentation for that provider or the Core API reference.

    Available Faker domains include:

    • Core: Basic faker functionality.
    • Books: Book-related data.
    • Commerce: Commercial and retail data.
    • Creatures: Animal and creature data.
    • Databases: Database-related data.
    • Edu: Educational data.
    • Games: Gaming-related data.
    • Humor: Jokes and humor.
    • JapaneseMedia: Japanese media content.
    • Lorem: Placeholder text (Lorem Ipsum).
    • Misc: Miscellaneous data.
    • Movies: Movie-related data.
    • Music: Music-related data.
    • Sports: Sports-related data.
    • Tech: Technology and hardware data.
    • Travel: Travel and tourism data.
    • TvShows: Television show data.
  7. Generate unique values for a single function (Local Unique)

    master

    If you only need uniqueness for a specific function call rather than an entire provider, use the unique property on the provider. This is known as a "local" unique generator.

    Local generators are independent of the global configuration. They do not respect global exclusion rules and they do not require the provider to be enabled via faker.unique.configuration.

    val faker = Faker()
    
    // This specific call is unique
    repeat(10) { faker.address.unique.country() }
    
    // This call is NOT necessarily unique (unless Address is enabled globally)
    repeat(10) { faker.address.city() }
  8. Generate unique data with Faker

    master
    Kotlin-Faker supports unique data generation. This was introduced in version 1.16.0 and allows you to ensure that the values generated by a specific Faker instance or its providers are not repeated. You can also configure exclusions for the global unique generator.
  9. Generate unique random values

    master

    The Faker#random property supports the generation of unique values. You can implement uniqueness at two levels:

    1. Local generation: Uniqueness is managed at the data-generator level.
    2. Global generation: Uniqueness is managed at the faker level.

    For detailed usage of the unique generator, refer to the Generating Unique Values documentation.

  10. Understand the structure of `Faker().source`

    master
    The Faker().source property provides access to the underlying dictionary files used by the library. These sources are defined in YAML format (e.g., en/source.yml) and serve as the raw data templates for generating localized content. While the library primarily uses these to populate faker providers, the source files themselves represent the mapping of keys to their respective localized string templates.
  11. Licensing for UI Faces avatars

    master
    As of 2024-10-15, the AI-generated avatars on UI Faces are distributed under terms that allow for both internal and commercial use. Images generated by OpenAI's DALL-E can be freely utilized in personal projects and commercial applications without licensing restrictions. For full details, refer to the uifaces_licenses.png file in this repository or visit the official uifaces licenses page.