Coder Social home page Coder Social logo

thisisqubika / fakeit Goto Github PK

View Code? Open in Web Editor NEW
535.0 24.0 49.0 728 KB

The Kotlin fake data generator library!

License: MIT License

Kotlin 100.00%
android android-library fakeit library open-source data-faker tests test-driven-development utility utility-library

fakeit's Introduction

Fakeit

alt text

This library is a port of the Ruby gem Faker. It generates realistic fake data — like names, emails, dates, countries — for a variety of scenarios, including automated testing and database population.

The library was originally created for Android projects, but it can be used in any Java or Kotlin project.

Download

You can use either Maven:

<dependency>
  <groupId>com.github.moove-it</groupId>
  <artifactId>fakeit</artifactId>
  <version>v0.5</version>
</dependency>

or Gradle:

// In your project's build.gradle
allprojects {
  repositories {
    maven { url 'https://jitpack.io' }
  }
}

//In your module's build.gradle
dependencies {
  compile 'com.github.moove-it:fakeit:v0.5'
}

Basic Usage

Fakeit can be used in Java and Kotlin applications - no Android context needed!

Run the sample app to check all the available models and generate some random values.

First you need to initialize Fakeit:

// Default locale is en for english data.
Fakeit.init()

// You can also pass a Locale or a String locale to change the language.
// See supported languages below.
Fakeit.init(locale)

Then, you need to import the module into each file where it will be used with:

import com.mooveit.library.Fakeit;

Finally, generate fake data like this:

Fakeit.name().lastName()
Fakeit.business().type()
Fakeit.address().city()
Fakeit.card().name()

Supported Data Models

  • Address
  • Ancient
  • App
  • Artist
  • Bank
  • Beer
  • Book
  • Business
  • Card
  • Cat
  • Chuck Norris
  • Code
  • Company
  • Compass
  • Date
  • Demographic
  • Educator
  • Esport
  • File
  • Food
  • Friends
  • Game of Thrones
  • Hacker
  • Harry Potter
  • Hey Arnold
  • Hipster
  • Internet
  • Job
  • Lord of the Rings
  • Lorem
  • Music
  • Name
  • Phone number
  • Pokemon
  • Rick and Morty
  • Rock band

Supported Languages

  • Catalan - Catalunya (ca-CAT)
  • Catalan (ca)
  • Danish - Denmark (da-DK)
  • Deutsch - Österreich (de-AT)
  • Deutsch - Schweiz (de-CH)
  • Deutsch (de)
  • English - Australia (en-AU)
  • English - Australian Slang (en-au-ocker)
  • English - Phonetic Nonsense from The Muppet's Swedish Chef (en-BORK)
  • English - Canada (en-CA)
  • English - Great Britain (en-GB)
  • English - India (en-IND)
  • English - Nepal (en-NEP)
  • English - Nigeria (en-NG)
  • English - New Zealand (en-NZ)
  • English - Pakistan (en-PAK)
  • English - Singapore (en-SG)
  • English - Uganda (en-UG)
  • English - United States (en-US)
  • English - South Africa (en-ZA)
  • English (en)
  • Spanish - Mexico (es-MX)
  • Spanish (es)
  • Farsi (fa)
  • Finnish - Finland (fi-FI)
  • French (fr)
  • Hebrew (he)
  • Indonesian (id)
  • Italian (it)
  • Japenese (ja)
  • Korean (ko)
  • Norwegian - Norway (nb-NO)
  • Netherlands (nl)
  • Polish (pl)
  • Portuguese - Brazil (pt-BR)
  • Portuguese (pt)
  • Russian (ru)
  • Slovak (sk)
  • Swedish (sv)
  • Turkish (tr)
  • Ukranian (uk)
  • Vietnamese (vi)
  • Chinese - China (zh-CN)
  • Chinese - Taiwan (zh-TW)

Unique Values

You can also use Fakeit to generate unique values:

Fakeit.getUniqueValue()

Questions and Issues

For bug reports and feature requests, use Github issue tracker

Contributing

See the contribution guide.

License

MIT

Fakeit is maintained by © Moove-it

fakeit's People

Contributors

gusaaaaa avatar isaintmartin avatar jeasmine avatar jorions avatar jotaemepereira avatar minibugdev avatar nico-gonzalez avatar seriabov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fakeit's Issues

appcompat android dependency

* What went wrong:
Could not resolve all files for configuration ':compileClasspath'.
> Could not find com.android.support:appcompat-v7:25.0.1.
  Searched in the following locations:
      https://repo1.maven.org/maven2/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.pom
      https://repo1.maven.org/maven2/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.jar
      http://dl.bintray.com/jetbrains/spek/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.pom
      http://dl.bintray.com/jetbrains/spek/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.jar
      https://jcenter.bintray.com/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.pom
      https://jcenter.bintray.com/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.jar
      https://jitpack.io/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.pom
      https://jitpack.io/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.jar
  Required by:
      project : > com.github.moove-it:fakeit:v0.5

I am pretty new to Kotlin as a whole and was trying to use this package in a spark app, it seems i need to also have this android dependency?
I saw there was another issue that was closed that said it removed all android deps.

Add pending models

Add this faker pending models:

  • Avatar
  • Bitcoin
  • Boolean
  • Business (some fields missing)
  • Coffee
  • Crypto
  • Demographic (some fields missing)
  • Dessert
  • Dragon Ball
  • File (some fields missing)
  • Fillmurray
  • Finance
  • Id Number
  • Lorem pixel
  • Markdown
  • Mata (maths)
  • Number
  • Omniauth
  • Place hold it
  • RuPaul
  • Shakespeare
  • Slack Emoji
  • Space
  • Star Wars
  • Superhero
  • Team
  • Time
  • Twin Peaks
  • Twitter
  • University
  • Vehicle
  • Version
  • Yoda
  • Zelda

Can't use it from unit tests in Android

When executed from a unit test in Android, Fakeit.init() throws an exception:

org.yaml.snakeyaml.error.YAMLException: java.io.IOException: Stream closed

at org.yaml.snakeyaml.reader.StreamReader.update(StreamReader.java:200)
at org.yaml.snakeyaml.reader.StreamReader.(StreamReader.java:60)
at org.yaml.snakeyaml.Yaml.load(Yaml.java:381)
at com.mooveit.library.Fakeit.getValues(Fakeit.kt:79)
at com.mooveit.library.Fakeit.(Fakeit.kt:69)
at com.mooveit.library.Fakeit.(Fakeit.kt:49)
at com.mooveit.library.Fakeit$Companion.fakeitInit(Fakeit.kt:233)
at com.mooveit.library.Fakeit$Companion.initWithLocale(Fakeit.kt:253)
at com.mooveit.library.Fakeit$Companion.initWithLocale(Fakeit.kt:259)
at com.mooveit.library.Fakeit$Companion.init(Fakeit.kt:247)
at xx.xxxxxx.xxxxx.viewmodels.LibraryViewModel.(LibraryViewModel.kt:104)
at xx.xxxxxx.xxxxx.SMMLibraryNavTests.setup(SMMLibraryNavTests.kt:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

Remove application tag in library module

<application> tag in AndroidManifest.xml is not necessary for a library module.

Sometimes it causes compile error even:

Error:Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : Attribute application@label value=(@string/app_name) from AndroidManifest.xml:8:4-36
	is also present at [com.github.moove-it:fakeit:v0.2] AndroidManifest.xml:13:9-49 value=(@string/application_name).
	Suggestion: add 'tools:replace="android:label"' to <application> element at AndroidManifest.xml:5:2-20:16 to override.

Random numbers and booleans?

Maybe I'm missing something, but doesn't this library have methods to generate simple random numbers and booleans...? If not, why? That's pretty much standard.

Add Kotlin sample app

Righ now we have a Java sample app, we should show the usage of the app in a Kotlin example also.

Add unit tests

We need a set of unit tests to ensure the right procedure of the core of parsing .yml values.

Can't initialize Fakeit

As soon as I try to initialize Fakeit with any language, for example Fakeit.initWithLocale(Locale.GERMAN), the app crashes.

The exception I get:

FATAL EXCEPTION: main
Process: xxx.yyy.zzz, PID: 2274
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762) 
Caused by: java.io.FileNotFoundException: library/src/main/assets/locales/de-DE.yml (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.(FileInputStream.java:146)
at com.mooveit.library.Fakeit.getValues(Fakeit.kt:81)
at com.mooveit.library.Fakeit.(Fakeit.kt:71)
at com.mooveit.library.Fakeit.(Fakeit.kt:51)
at com.mooveit.library.Fakeit$Companion.fakeitInit(Fakeit.kt:236)
at com.mooveit.library.Fakeit$Companion.initWithLocale(Fakeit.kt:256)
at xxx.yyy.zzz.HomeFragment.onClick(HomeFragment.kt:63)
at android.view.View.performClick(View.java:5624)
at android.view.View$PerformClick.run(View.java:22441)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6316)
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762) 

The .yml files seem to be missing but I don't know how to fix this

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.