测者的测试技术手册:自动的自动化EvoSuite 自动生成JUnit的测试用例

EvoSuite简介

EvoSuite是由Sheffield等大学联合开发的一种开源工具,用于自动生成测试用例集,生成的测试用例均符合Junit的标准,可直接在Junit中运行。获得了Google和Yourkit的支持。bash

intelliJ IDEA插件

打开IDE,进入setting(mac版本是Preferences),选择plugins,点击Browse repositories,搜索EvoSuite Plugin,而后选择Install plugin。maven

Maven 插件引入

当前支持Maven3.1以上版本。 Maven工程能够经过引入EvoSuite的Maven插件来生成新的测试用例。使用Maven插件有以下好处:工具

  • 一、能够和Jenkins结合,方便快速的运行EvoSuite测试

  • 二、测试用例生成在pom.xml文件约定好的工程目录下ui

  • 三、经过Maven的依赖引入EvoSuite,无需单独下载独立的jar文件。spa

插件的引入以下:插件

<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>复制代码

引入依赖:code

<dependency>  <groupId>org.evosuite</groupId>  <artifactId>evosuite-standalone-runtime</artifactId>  <version>${evosuiteVersion}</version>  <scope>test</scope></dependency>复制代码

设定版本的变量(最新版能够在http://www.evosuite.org/downloads/查询):xml

<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

详情参见官方文档:http://www.evosuite.org/documentation/

关注测者,关注测试

相关文章
相关标签/搜索