How to Create Test Data using Faker.js

in Education18 days ago

If you are into programming and development you often need to create the test data and for that you can use variety of online services. You can also create using the random data options that we have on internet. But apart from that I came across some modules that allow you to do test data creation.

So what is faker.js? It is npm module that takes some of the inputs from the user and it can create the random test data. This would help with the large data before you can test out the apps and the apps which needs some sample data.

First thing you should do is make sure to setup the fakerjs module. You can use the below code.

npm install faker


After you install your module. Next you can use it in any project that you have and you can build over the module that you have.

So let's take a look at the code where you have to think over the data that you can generate using the code below. So here the name, surname is something you want to create the demo data with the same. Below code can be a good option for you to create a new such sample data. Use a loop to generate the amount of the rows of data that you wish to generate the sample data.

Next thing is creating a sample data that you would love to try out which is making use of the domain name and the ip address sample data. Say you have the network related application and also those who have the app where they need some of such a lot of sample data. They should be making use of the below code for the data. I am posting the code snippet which you can hold for the reference.

Now I suppose you kind of liked this fakerjs. I would say experiment with this for your own use case. You can create variety of samples using this and it would require just the context being called for the test data in the fakerjs.

Fakerjs is a good test data and these examples you can easily do. There are countless other examples for you to go through as well. Documentation has many other options for you to explore and you will learn a lot in this while you experiment with variety of faker.context() options out there. So hopefully this tutorial helps you :)

Sort:  

Congratulations @skysnap! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

You received more than 10000 upvotes.
Your next target is to reach 15000 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Check out our last posts:

LEO Power Up Day - May 15, 2024