XUtils

faker-cxx

C++20 Faker library for generating fake (but realistic) data for testing and development. [MIT]


🎯 Goal

The goal of Faker C++ is to provide a library similar to Faker.js for C++ community. Faker C++ helps with the creation of realistic and customizable fake data for testing and development purposes within C++ applications.

#include

#include “faker-cxx/Date.h” #include “faker-cxx/Internet.h” #include “faker-cxx/Location.h” #include “faker-cxx/String.h”

// or #include “faker-cxx/Faker.h” for all modules

int main() {

const auto id = faker::string::uuid();
const auto email = faker::internet::email();
const auto password = faker::internet::password();
const auto city = faker::location::city();
const auto streetAddress = faker::location::streetAddress();

std::cout << id << std::endl;               // 58018063-ce5a-4fa7-adfd-327eb2e2d9a5
std::cout << email << std::endl;            // Lois_Hauck@hotmail.com
std::cout << password << std::endl;         // @cWLwgM#Knalxeb
std::cout << city << std::endl;             // Sayre ville
std::cout << streetAddress << std::endl;    // 1716 Harriet Alley

return 0;

} “`

Consuming library with CMake (CMake 3.22 or newer)

  1. Add faker to git submodules (execute in project root):

    mkdir externals && cd externals
    git submodule add https://github.com/cieslarmichal/faker-cxx.git
    git submodule update --init --recursive
    
  2. Link with library:

    set(BUILD_TESTING OFF)
    
    
    add_subdirectory(externals/faker-cxx)
    
    
    add_executable(main Main.cpp)
    
    
    target_link_libraries(main faker-cxx)
    

Building the library with Conan

The library can be built using Conan package manager to solve external dependencies. To build the library with Conan, follow the steps below:

  1. Install required dependencies:

    conan install conanfile.txt --build=missing
    
  2. Build the library:

    cmake --preset=conan-release -DUSE_SYSTEM_DEPENDENCIES:BOOL=ON
    cmake --build --preset=conan-release
    

📘 Credits

Thanks to all the people who already contributed to Faker!

Examples

This project offers examples to demonstrate how to use the Faker C++ library. These examples can be found in the examples folder of the project repository. The examples showcase various modules of the library and provide code snippets that illustrate how to generate fake data using Faker C++.

📝 Changelog

Detailed changes for each release are documented in the release notes.


Articles

  • coming soon...