2014-02-26 60 views

回答

0

這些帖子有點過時了,雖然我不能說出接受的答案,但其他一些答案仍然有效。 Play和specs2自2012年以來有一些相對較大的變化,所以我會提供一個我知道今天會工作的例子(我每天都會使用)。

我做了兩件事情,使它更容易隔離測試。首先,我命名空間所有我的測試類。根據包test.integration進行集成測試,並在test.unit下進行單元測試。其實我去有點超出了,例如:test.unit.modelstest.unit.controllers.users

然後我可以運行所有的我的模型試驗用:test-only test.unit.models.*

我也覺得有幫助的標記每個單獨測試的情況下,無論是我正在測試的函數的名稱或其他有用的描述符。

package test.unit.models 

import org.specs2.mutable._ 
import play.api.test._ 
import play.api.test.Helpers._ 
import models.User 

object UserSpec extends Specification { 

    "The user model" should { 

     tag("create") 
     "successfully create a new user" in new WithApplication { 

       .... 

     } 

     ... 
    } 

} 

現在我可以有超過其測試與運行更加精細的控制:

test-only test.unit.models.UserSpec -- include create 

也許我想運行所有的單元測試,除了那些被標記的「創造」:

test-only test.unit.* -- exclude create 

通配符也可以放在完整軟件包名稱的任何位置。例如,如果您有兩個型號規格:test.unit.models.UserSpectest.unit.models.UserCountrySpectest-only test.unit.models.User*會同時運行。

相關問題