Simple use of automated Unit Testing Tool EvoSuite and unit testing evosuite

Source: Internet
Author: User

Simple use of automated Unit Testing Tool EvoSuite and unit testing evosuite
1. Introduction to EvoSuite

EvoSuite is an open-source tool jointly developed by Sheffield and other universities. It is used to automatically generate test case sets. All generated test cases comply with Junit standards and can be run directly in Junit.

Using this automated testing tool can greatly improve the development efficiency of testers while ensuring code coverage. However, it can only assist in testing and cannot completely replace manual testing. Manual judgment is required if the test cases are correct or not.

EvoSuite official website for http://www.evosuite.org

EvoSuite GitHub https://github.com/EvoSuite/evosuite

EvoSuite Questions and Answers http://stackoverflow.com/questions/tagged/evosuite

Ii. Install the EvoSuite Eclipse plug-in

The EvoSuite plug-in requires the runtime environment of Java 8 and only supports the Lunar and Mars versions of Eclipse. After installing Java 8 (if there are multiple Java development environments in the system, set the default jre of Eclipse to Java 8. copy the jar file to the jre8/lib/folder. After that, Java 8 can ensure the normal operation of the EvoSuite plug-in.

 

The installation process is as follows (the installation process is listed in detail due to problems that may occur during the installation ):

Figure 1

2. Click Add... Button. The following dialog box is displayed.

 

Figure 2

 

3. Enter the EvoSuite Eclipse plug-in address in the Location bar: http://www.evosuite.org/update, click OK, the result is as follows

Figure 3

4. Select Junit Test Generation and click Next. The result is as follows:

 

Figure 4

 

5. The running time may be too long. Please wait. After the running is completed, the result is as follows:

Figure 5

 

6. Click Next, select I accept the terms of license agreement, and click Finish. the Installing Software dialog box is displayed. After a period of time, the following dialog box is displayed.

Figure 6

 

7. Click OK. After a period of time, the following dialog box appears.

 

Figure 7

 

8. Click the "Yes" button. After Eclipse is restarted, select a java class file at will. If a mark is displayed, the plug-in is successfully installed.

Figure 8

Iii. simple use of EvoSuite

Select the class to be tested, right-click, and select Generate tests with EvoSuite. the test case is generated and generated in the evosuite-tests folder of the project. The generated test class is the standard Junit 4 test class, which can be fully tested in accordance with Junit 4 operation specifications.

Note: When you use this tool to test Servlet-related classes in a Web project, the tool cannot load the jar package of the level-2 directory, therefore, the jar packages in the Server Runtime Library and Web App Library should be re-imported into the project.

Iv. EvoSuite parameter settings

Click Windows> Preferences and find EvoSuite to set it. The setting interface is as follows:

Figure 9

Parameter description:

1. Enable Markers and Quick-fixes: select this option to generate a prompt mark in the generated test class.

2. Time for EvoSuite to improve code coverage (s): maximum Time allowed for EvoSuite to improve code coverage when generating test classes

3. Inactive time before other classes will be tested (s ):

4. Show lines EvoSuite couldn't cover:

5. Show lines the compiler may have removed:

6. Automatic test on save:

7. Organize imports:

8. Print test comments: If this option is selected, detailed comments will be added to each test method in the test class.

V. Generation of Junit Test report

Select a project, right-click, select Export-> General-> Ant Buildfiles, set Name for Ant buildfile and Junit output directory (do not change the default value), and click Finish, the build. xml file, select build. xml, right-click and select Run As-> Ant Build... Select junitreport and the test class to generate the test report, select Sort targets, and click Run to view the test report in the junit folder.

 

After you click index.html, the example result is as follows:

Figure 10

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.