2012-11-26 30 views
7

我正在爲我的scala軟件寫一個specs2 Unittest。執行效果良好。我唯一的問題是,在完成所有測試後我需要清理。我無法找到任何解決方案。在所有測試完成後有沒有辦法執行某些功能?最終清理specs2

回答

9

您需要在您的規格的末尾添加Step

import org.specs2.mutable._ 

class MySpec extends Specification { 

    // lots of examples here 

    // cleanup there 
    step(cleanUp()) 
} 
+0

謝謝你這個作品相當不錯。 –

+1

是否有可能,如果任何步驟引發異常,然後不運行cleanUp? – Robertiano

+0

是的,但那樣會失敗。 – Eric

0

您可以嘗試使用with After後執行def after函數。

例子:

class Context extends Specification { 
.... 
} 

trait trees extends mutable.After { 
    def after = cleanupDB 
} 
+0

這是否工作,爲規範?如下所示:class Spec extends with After {...} –

+1

*在每次測試後運行*之後,OQ指的是* all *測試後的清理。 –