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
Eg:
java -classpath D:\randoop-3.0.8\randoop-all-3.0.8.jar
2.2 To generate the Test Cases for the particular class:
java -classpath D:\randoop-3.0.8\randoop-all-3.0.8.jar
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
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
2. If there are a list of classes:
--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.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
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.