2017-06-14 85 views
0

我用wordspec一种行使下列情形嵌套测试用例

case class Assertion(expected:Any, actual:Any) 
case class TestCases(name:String, assertions:List[Assertions]) 
val testCases = List[TestCases] 

"Testcases" should { 
    testCases.foreach(testCase =>{ 
    s"${testCase.name}" should { 
     testCase.assertions.foreach(assertion=>{ 
     assert(assertion.expected == assertion.actual) 
     }) 
    } 
    }) 
} 

现在事情已经改变了一下,现在的测试用例是Future[List[Assertion]] instead of List[Assertion]. 我尝试使用AsyncFlatSpec但我有嵌套的测试问题情况,你可以在上面看到,当测试与嵌套测试用例运行时,它说,空测试套件..

val testCasesFuture = Future[List[TestCases]] 

behavior of "Testcases" 
testCasesFuture.foreach(testCases =>{ 
    testCases.foreach(testCase =>{ 
     it should s"${testCase.name}" in { 
     testCase.assertions.foreach(assertion=>{ 
      assert(assertion.expected == assertion.actual) 
     }) 
    } 
    }) 
}) 

回答

0

花时间调试的很多,我终于找到了答案后,我搬到了未来的断言和内解决了这个问题..这里的代码片段更好地理解

import org.scalatest.AsyncWordSpec 

import scala.concurrent.Future 

class FutureSpec extends AsyncWordSpec { 
    case class Assert(expected: Any, actual: Any) 
    case class Assertion(name: String, assert: Future[Assert]) 
    case class TestCase(name: String, assertion: List[Assertion]) 
    val testCases = List(TestCase("sample", List(Assertion("first", Future(Assert(1, 1)))))) 

    "TestCase" should { 
    testCases.foreach { testCase => 
     { 
     testCase.name should { 
      testCase.assertion.foreach(assertion => { 
      assertion.name in { 
       assertion.assert.map(a => assert(a.expected == a.actual)) 
      } 
      }) 
     } 
     } 
    } 
    } 
}