Automatic Unit Test Generation

Posted By : Sakshi Dewan Gandhi | 30-Apr-2018

Nowadays, technology has grown to the extent that we have got all the necessary tools and services available in the Online market which we can make use f to get something meaningful out of it. For speeding up the task of Testing we use various Automation Tools, Similarly, we can also use various Tools to generate Test Cases, particularly Unit Test Cases. One such Tool is "Randoop" which is very useful to generate Test Cases for Java. Let's see how it generate Test Cases for Java Classes.

 

The concept of the Process:

 

The main idea of using Randoop is to generate unit test cases so that all the test cases are covered logically. What Randoop does is it fetches all the Input Conditions from the ClassFile and then generate all the possible outcome of those inputs as its Output in the form of Test Suits. Now, Once these Test Suits are generated, Software Tester of Developer can refine or take a complete list of test cases in the test suits to run and get to know which condition is Failing through the Output File. Following are the Steps in the Process for the same:

 

STEPS:

 

1. Install the Software Randoop from the GitHub, following is the URL for that:

https://github.com/randoop/releases/download/v3.0.8/randoop-3.0.8.zip

 

2. Run the following command to generate the test cases:

2.1 The below command will generate Test Cases for all the Classes in the respective Folder.


java -classpath path...of classes for which the test suit is needed....then

jarfile path----randoop main.Main gentests -testclass-testing randoop

Eg:

java -classpath D:\randoop-3.0.8\randoop-all-3.0.8.jar randoop main.Main help gentests

2.2 To generate the Test Cases for the particular class:

java -classpath D:\randoop-3.0.8\randoop-all-3.0.8.jar randoop main.Main help gentests --testclass=TestingRandoop

 

3. Input is the Class File and following two Output Files are generated:

--Regression Tests.
--Error Tests.

 

4.Generate the Test Cases with Input and Output Limit:

It tries to take random Inputs which we can Refine. Once the User Input Validation is completed then it tells how many JUnit test cases are going to generate automatically. These test cases are huge in number, for example, there can be as much as 3000 test cases for one test class. By refining only those inputs which we want only those get generated. In the bin folder, we get its Output.

There is one point to add here that, Randoop Test Cases are not readable. One thing for sure it can not be analyzed. Only take inputs and based on that generate outputs: It will generate the Output where you are in the Command Prompt.

REFINE IT (Limiting the User Inputs) Example:

1. If there is only one class:

java -classpath D:\randoop-3.0.8\randoop-all-3.0.8.jar randoop main. Main help gentests --InputLimit=100 --Outputlimit=100

2. If there are a list of classes:
gentests ---classlist

--InputLimit=100 --Outputlimit=100

That's All, so this way we can make test cases and get our Regression Testing Done. It could save a lot of time.

 

 

 

 

 

 

 

 

Related Tags

About Author

Author Image
Sakshi Dewan Gandhi

Sakshi has experience into Testing, which comprises of Functional, Performance and End-to end-System Testing. She has worked in various domains like: Telecom, E-Commerce, E-Learning and Language Translation.

Request for Proposal

Name is required

Comment is required

Sending message..