2011年4月20日水曜日

Scala specsの実行順序



import org.junit.runner.RunWith
import org.specs.Specification
import org.specs.runner.{JUnit, JUnitSuiteRunner}

@RunWith(classOf[JUnitSuiteRunner])
class ExecuteOrderTest extends Specification with JUnit{

doBeforeSpec{
println("Do once before all specs")
}
doAfterSpec{
println("Do once after all specs")
}
"First" should {
doFirst{
println("Do once before all test in First")
}
doBefore{
println("Do before every test in First")
}
"hello" in {

println("Hello world")
}
"good by" in {
println("Good by world")
}
doAfter{
println("Do after every test in First")
}
doLast{
println("Do once after all test in First ")
}
}
"Second" should {
doFirst{
println("Do once before all test in Second")
}
doBefore{
println("Do before every test in Second")
}
"hello2" in {
println("Hello world2")
}
"good by2" in {
println("Good by world2")
}
doAfter{
println("Do after every test in Second")
}
doLast{
println("Do once after all test in Second ")
}
}


}


実行結果

Do once before all specs

Do once before all test in First
Do before every test in First
Hello world
Do after every test in First
Do before every test in First
Good by world
Do after every test in First
Do once after all test in First

Do once before all test in Second
Do before every test in Second
Hello world2
Do after every test in Second
Do before every test in Second
Good by world2
Do after every test in Second
Do once after all test in Second

Do once after all specs