我正在爲我的scala軟件寫一個specs2 Unittest。執行效果良好。我唯一的問題是,在完成所有測試後我需要清理。我無法找到任何解決方案。在所有測試完成後有沒有辦法執行某些功能?最終清理specs2
7
A
回答
9
您需要在您的規格的末尾添加Step:
import org.specs2.mutable._
class MySpec extends Specification {
// lots of examples here
// cleanup there
step(cleanUp())
}
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 *測試後的清理。 –
相關問題
- 1. 試圖用閉包編寫測試最終失敗Specs2
- 2. C清理錯誤/終止
- 3. 子進程終止清理
- 4. 在程序終止時清理GLPK最乾淨的方法
- 5. Specs2/Neo4j - 使用Specs2的ImpermanentGraphDatabase
- 6. 搖籃和Specs2:Specs2-HtmlOutput
- 7. 需要澄清最終的StringBuffer對象
- 8. 尋找最終經理ID
- 9. Scotty應用程序終止後清理
- 10. 終止前清理緩衝區
- 11. 非最終類中的代理最終方法
- 12. 如何最好地中斷清理和終止zeroMQ輪詢方法
- 13. 關閉,處理,最終確定,GC,Idisposable,...你有清楚的描述他們嗎?
- 14. 使用ScheduledExecutorService時執行最終清理計劃任務的位置
- 15. Specs2 - 斯卡拉
- 16. 玩JSON - 與Specs2
- 17. 玩+ specs2 + scalacheck?
- 18. Scala specs2的Stackoverflow
- 19. 使用Specs2
- 20. Pascal清算終端
- 21. Java中的異常處理 - 最終
- 22. 如何處理靜態最終變量
- 23. 批處理腳本 - FINDSTR最終結果?
- 24. 最終化/後處理鏈方法
- 25. 顛覆最佳實踐和清理
- 26. 清理Unicode輸入的最佳做法
- 27. Android清單錯誤清單文件不具有最終換行符結束
- 28. Specs2 IT環境tearDown
- 29. 無法驗證specs2
- 30. 最終與非最終正常變量
謝謝你這個作品相當不錯。 –
是否有可能,如果任何步驟引發異常,然後不運行cleanUp? – Robertiano
是的,但那樣會失敗。 – Eric