轉載: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文件夾中能夠看到測試報告。