转载:https://www.cnblogs.com/hughding/p/evosuite.htmlhtml
EvoSuite是由Sheffield等大学联合开发的一种开源工具,用于自动生成测试用例集,生成的测试用例均符合Junit的标准,可直接在Junit中运行。
经过使用此自动测试工具可以在保证代码覆盖率的前提下极大地提升测试人员的开发效率。可是只能辅助测试,并不能彻底取代人工,测试用例的正确与否还需人工判断。git
EvoSuite官网为http://www.evosuite.orggithub
EvoSuite GitHub https://github.com/EvoSuite/evosuite工具
EvoSuite问题及解答http://stackoverflow.com/questions/tagged/evosuite测试
EvoSuite 插件须要Java 8 的运行环境,而且只支持Eclipse的Lunar和Mars版本,在安装完毕Java 8以后(若系统中有多种Java开发环境,需将Eclipse的默认jre设置成Java 8 版本),须要将jdk1.8/lib/tools.jar 文件复制到 jre8/lib/ 文件夹当中,在此以后Java 8才能保证EvoSuite插件的正常运行。
选中须要测试的类,右击鼠标,选择Generate tests with EvoSuite ,则会生成测试用例,测试用例生成在项目中的evosuite-tests文件夹内。生成的测试类为标准的Junit 4 测试类,能够彻底按照Junit 4 的操做规范对其测试。
注意:在使用此工具测试Web项目中和Servlet相关的类时,工具加载不到二级目录的jar包,所以应该把 Server Runtime Library和Web App Library中的jar包再从新导入到工程当中。ui
点击Windows->Preferences ,查找到EvoSuite便可对其进行设置,设置界面以下spa
参数说明:插件
Enable Markers and Quick-fixes:选中此选项会在生成的测试类中产生提示的标记code
Time for EvoSuite to improve code coverage(s): 容许EvoSuite生成测试类时改进代码覆盖率的最大时间xml
Inactive time before other classes will be tested(s):
Show lines EvoSuite couldn’t cover:
Show lines the compiler may have removed:
Automatic test on save:
Organize imports:
Print test comments:选中此项会在测试类中每个测试方法上加上详细地注释
选中项目,右击鼠标,选择Export->General->Ant Buildfiles后,设置Name for Ant buildfile和Junit output directory(通常不修改使用默认值),点击Finish,项目中出现build.xml文件,选中build.xml,右击鼠标,选择Run As->Ant Build…后,选中junitreport和要生成测试报告的测试类,选中Sort targets后,点击Run按钮,在junit文件夹中能够看到测试报告。