官方網站為:https://www.evosuite.org/
1、官網找到以下連結

2、maven 插件接入
引入org.evosuite.plugins插件
<!--evoSuite 插件-->
<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>
并且在屬性中加入相應的變量:
<properties>
<evosuiteVersion>1.0.6</evosuiteVersion>
</properties>
加入evosuite運作包
<dependency>
<groupId>org.evosuite</groupId>
<artifactId>evosuite-standalone-runtime</artifactId>
<version>${evosuiteVersion}</version>
<scope>test</scope>
</dependency>
使用EvoSuite的Java代理時,還需要配置surefire插件來運作EvoSuite測試的初始化監聽器。當EvoSuite自動測試與手工編寫的測試混合使用時。如下所示:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
<configuration>
<skipTests>true</skipTests>
<properties>
<property>
<name>listener</name>
<value>org.evosuite.runtime.InitializingListener</value>
</property>
</properties>
</configuration>
</plugin>
如何使用EvoSuite Maven插件提供了以下目标:
1)“generate”->這是用來生成帶有EvoSuite的測試用例的。将為所有子子產品中的所有類生成測試。您需要確定代碼已編譯,例如“mvn compile”evosuite:generate”. 此目标為以下參數:“”memoryInMB“:EvoSuite允許配置設定的兆位元組總量(預設值800)”cores“:EvoSuite可以使用的CPU核心總數(預設值1)*”timeInMinutesPerClass“:EvoSuite可以為每個類生成測試花費多少分鐘(預設值2)
2)“info”->提供到目前為止生成的所有測試3)“導出”->預設情況下,EvoSuite在“.EvoSuite”檔案夾中建立測試。通過使用“export”,生成的測試将被複制到另一個檔案夾,該檔案夾可以通過“targetFolder”選項設定(預設值為“src/test/java”)。注意:如果不将測試導出到帶有“mvn”的“src/test/java”中evosuite:export,則像“mvn test”這樣的指令将不會執行這些測試,因為它們的源代碼不在建構路徑上。您可以使用“build helper maven plugin”插件添加自定義源檔案夾,例如:
<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>
運作使用:
1、如果等于,則不需要使用如果這樣做,那麼您将得到編譯錯誤,因為每個測試将在類路徑上出現兩次)。注意:另一種方法是重寫以指向customFolder等于“.evosuite/evosuitetests”,則不需要使用evosuite:export”.(如果這樣做,那麼您将得到編譯錯誤,因為每個測試将在類路徑上出現兩次)。注意:另一種方法是重寫“”以指向{customFolder}。
2、如果希望隻在EvoSuite生成的測試上運作“mvn test”(例如,如果在Jenkins上有兩個不同的配置/配置檔案,一個隻運作現有的手動測試,另一個隻運作EvoSuite測試),這将非常有用。
3、“clean”->删除“.evosuite”檔案夾中的所有資料,該檔案夾用于存儲迄今為止生成的所有最佳測試。
4、“prepare”->需要運作與現有測試混合的EvoSuite測試,例如“mvn”evosuite:prepare test”. 如前所述,最好隻配置evosuite插件以始終運作它。
運作指令如下:
mvn -DmemoryInMB=2000 -Dcores=2 evosuite:generate evosuite:export test
測試代碼生成截圖: