Java Faker With IntelliJ Maven Project [Software Development Engineer in Test Article Series Part 8]
Up to now, I have written 7 articles which are mostly about the structure of software testing. From this article, I am starting the technical part of software testing. You can read the previous articles from here.

I assume that the reader knows coding with java, and is familiar with IntelliJ IDE.
Technical prerequisites:
- IntelliJ IDE must be installed.
- JDK must be installed.
Question: What is Java Faker?
Java Faker is a fake data generator.
Question: Why do we need it?
In order to perform software tests, we almost always need data to use in our test steps.
For example, you are testing a “sign up with email” functionality.
You need email addresses to write in the email text box. You need valid and invalid email addresses for testing both negative and positive test scenarios.
Thanks to Java Faker, you can always populate a random valid email address to use in your tests.
Question: Do developers use it?
Sometimes. They use Java Faker for unit tests. Like a SDET, they also need to test valid and email addresses in their unit tests.
Moreover, if the database or API is not ready yet, developers can use random data from Java Faker when they need sample data.
Where is Java Faker? Where to find it?
Java Faker is a public Java tool. It has a public repository on GitHub. And there is the document page of Java Faker.
How to use Java Faker?
First, you have to add Java Faker as a dependency to your project.
What project?
Any project coded with Java.
How to add?
Follow the pictures for adding Java Faker to an IntelliJ Maven project:














Now, we added Java Faker library to our project.
As you see in the last picture we created a Faker object.
As you noticed from the top of the class, that Faker class is defined in the “com.github.javafaker” package that we just added as a dependency.

In the image above; a Faker object is created and an animal name is generated. As you see, codes are the same but outputs are different. So Faker is populating randomly.


In the image above, there are two different Faker objects; one is created with Turkish Local, another is created with US Local. As you see the first name generation is different based on the local settings of instances.
What kind of topics do we have in Java Faker, like animals and names?
According to the documentation, these are the main data topics:
- Address
- Ancient
- Animal
- App
- Aqua Teen Hunger Force
- Artist
- Avatar
- Back To The Future
- Aviation
- Basketball
- Beer
- Bojack Horseman
- Book
- Bool
- Business
- ChuckNorris
- Cat
- Code
- Coin
- Color
- Commerce
- Company
- Crypto
- DateAndTime
- Demographic
- Disease
- Dog
- DragonBall
- Dune
- Educator
- Esports
- EnglandFootBall
- File
- Finance
- Food
- Friends
- FunnyName
- GameOfThrones
- Gender
- Hacker
- HarryPotter
- Hipster
- HitchhikersGuideToTheGalaxy
- Hobbit
- HowIMetYourMother
- IdNumber
- Internet
- Job
- Kaamelott
- LeagueOfLegends
- Lebowski
- LordOfTheRings
- Lorem
- Matz
- Music
- Name
- Nation
- Number
- Options
- Overwatch
- PhoneNumber
- Photography
- Pokemon
- Princess Bride
- Relationship Terms
- RickAndMorty
- Robin
- RockBand
- Shakespeare
- Sip
- SlackEmoji
- Space
- StarCraft
- StarTrek
- Stock
- Superhero
- Team
- TwinPeaks
- University
- Weather
- Witcher
- Yoda
- Zelda
What kind of data do those main topics generate?
They all generate String data.
There are methods in those classes. These methods generate data mostly without parameters.
For example in the Address class there is a method
streetAddress()
and there is an overloaded version with a boolean parameter
streetAddress(boolean includeSecondary)
Let’s look the outputs:

What are all of these methods in all of those main classes?
I had the same curiosity. Then, I wrote a couple of codes to get all of the available methods with Java reflection. I iterate the main classes and their methods that have no parameters. I run those methods with a default Faker object and with a Turkish Localized Faker object. So, at the end, I could get a list of sample outputs based on two different localizations. The default local is EN. There is the GitHub of that short project: JavaFakerSamples. Just copy the class to your project or clone the all repository.
I put the outputs that I yielded from the JavaFakerSamples project in a Google Spreadsheet: JavaFaker Methods Without Parameters Outputs EN/TR.

With this output, you can have an opinion about the Faker methods and you become familiar with the localized outputs.
What else? Are we done with Java Faker?
There are some useful functions which can be used through the Faker object.
The numerify method returns a string with the ‘#’ characters, in the parameter, replaced with random numbers.

The letterify method returns a string with the ‘?’ characters, in the parameter, replaced with random characters.

The bothify method returns a string with the ‘?’ characters, in the parameter, replaced with random characters, and ‘#’ chracters replaced with random numbers.

The regexify method returns a random sequence based on a input regex pattern.

Lastly, I want to share the Random Service outputs:

Ok. We generated a lot of different data. I have power of random data generation. Where to use them?
In following articles we will use that data. This is an only preparation for our tests.