EvoSuite是由Sheffield等大學聯合開發的一種開源工具,用於自動生成測試用例集,生成的測試用例均符合Junit的標準,可直接在Junit中運行。獲得了Google和Yourkit的支持。bash
打開IDE,進入setting(mac版本是Preferences),選擇plugins,點擊Browse repositories,搜索EvoSuite Plugin,而後選擇Install plugin。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的插件將會對對應的子模塊的全部的類進行測試用例生成分析,再分析前須要保證對應代碼是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/
關注測者,關注測試