EvoSuite简介
intelliJ IDEA插件
打开IDE,进入setting(mac版本是Preferences),选择plugins,点击Browse repositories,搜索EvoSuite Plugin,然后选择Install plugin。
Maven 插件引入
当前支持Maven3.1以上版本。 Maven工程可以通过引入EvoSuite的Maven插件来生成新的测试用例。使用Maven插件有如下好处:
1、可以和Jenkins结合,方便快速的运行EvoSuite
2、测试用例生成在pom.xml文件约定好的工程目录下
3、通过Maven的依赖引入EvoSuite,无需单独下载独立的jar文件。
插件的引入如下:
<pluginManagement><plugins> <plugin> <groupId>org.evosuite.plugins</groupId> <artifactId>evosuite-maven-plugin</artifactId> <version>${evosuiteVersion}</version> <executions><execution> <goals> <goal> prepare </goal> </goals> <phase> process-test-classes </phase> </execution></executions> </plugin></plugins></pluginManagement> |
引入依赖:
<dependency> <groupId>org.evosuite</groupId> <artifactId>evosuite-standalone-runtime</artifactId> <version>${evosuiteVersion}</version> <scope>test</scope></dependency> |
设定版本的变量(最新版可以在http://www.evosuite.org/downloads/查询):
<properties> <evosuiteVersion>1.0.6</evosuiteVersion></properties> |
由于EvoSuite是生成的JUnit的文件,因此需要引入Junit的依赖。
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope></dependency> |
EvoSuite的使用
EvoSuite的插件将会对对应的子模块的所有的类进行测试用例生成分析,再分析前需要保证对应代码是build过的。通过插件选取或者mvn compile evosuite:generate 开始分析。
默认情况下会在模块目录下生成.evosuite目录,目录里面是测试用例,如果想要修改那么可以通过如下插件进行配置
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>1.8</version> <executions> <execution> <id>add-test-source</id> <phase>generate-test-sources</phase> <goals> <goal>add-test-source</goal> </goals> <configuration> <sources> <source>${customFolder}</source> </sources> </configuration> </execution> </executions></plugin> |
特别提醒:如果上面的变量${customFolder}是.evosuite/evosuite-tests,那么不需要再次执行evosuite:export
上文内容不用于商业目的,如涉及知识产权问题,请权利人联系博为峰小编(021-64471599-8017),我们将立即处理。