私は現在、Specs2ライブラリを使用してScalaPlayアプリケーションの一連のテストを作成しています。
テスト文字列が長すぎるため、コンパイルプロセス中にスタックオーバーフローエラーが発生したため、いくつかのクラスに分割しました。
問題は、マルチスレッドプロセスを使用してテストが同時に実行されることです。それらのテストの順序を指定する必要があります。これを行う方法はありますか?よろしく。
を仕様に追加することで、テストを順番に実行する必要があることを指定できますsequential
。
ユニット スタイルのテストを使用している場合は、sequential
テストの上の行にステートメントを配置します (仕様ドキュメントから借用した例)。
import org.specs2.mutable._
class HelloWorldSpec extends Specification {
sequential
"The 'Hello world' string" should {
"contain 11 characters" in {
"Hello world" must have size(11)
}
"start with 'Hello'" in {
"Hello world" must startWith("Hello")
}
"end with 'world'" in {
"Hello world" must endWith("world")
}
}
}
受け入れスタイルのテストを使用している場合は、の定義内にシーケンシャルを追加するだけですis
import org.specs2._
class HelloWorldSpec extends Specification { def is =
sequential ^
"This is a specification to check the 'Hello world' string" ^
p^
"The 'Hello world' string should" ^
"contain 11 characters" ! e1^
"start with 'Hello'" ! e2^
"end with 'world'" ! e3^
end
def e1 = "Hello world" must have size(11)
def e2 = "Hello world" must startWith("Hello")
def e3 = "Hello world" must endWith("world")
}
補足として、テストが長すぎるというよりも、ソフトウェアのエラーからスタック オーバーフロー エラーが発生している可能性があります。
class UsersSpec extends Specification with BeforeAll with Before {
def is = sequential ^ s2"""
We can create in the database
create a user $create
list all users $list
"""
import DB._
def create = {
val id = db.createUser("me")
db.getUser(id).name must_== "me"
}
def list = {
List("me", "you").foreach(db.createUser)
db.listAllUsers.map(_.name).toSet must_== Set("me", "you")
}
// create a database before running anything
def beforeAll = createDatabase(databaseUrl)
// remove all data before running an example
def before = cleanDatabase(databaseUrl)
お役に立てますように!