2017-10-05 36 views

回答

2

FunSuite.test定義在ScalaTestFunSpecLike性狀。它具有以下定義:

protected def test(testName: String, testTags: Tag*)(testFun: => Any /* Assertion */)(implicit pos: source.Position): Unit = { 
    // SKIP-SCALATESTJS-START 
    val stackDepth = 4 
    val stackDepthAdjustment = -2 
    // SKIP-SCALATESTJS-END 
    //SCALATESTJS-ONLY val stackDepth = 6 
    //SCALATESTJS-ONLY val stackDepthAdjustment = -6 
    engine.registerTest(testName, Transformer(testFun _), Resources.testCannotAppearInsideAnotherTest, "FunSuiteLike.scala", "test", stackDepth, stackDepthAdjustment, None, None, Some(pos), None, testTags: _*) 
} 

最重要的一點是,它註冊其執行的有效載荷,通過engine.registerTest(...)電話。從理論上說,你可以把它做這樣的認識mytest

class MyFunSuite 
extends FunSuite { 

    // User-defined test named mytest 
    protected def mytest(testName: String, testTags: Tag*)(testFun: => Any /* Assertion */)(implicit pos: source.Position) = { 
    test(testName, testTags: _*)(testFun)(pos) 
    } 
} 

你會再使用它,如下所示:

class MyTests 
extends MyFunSuite { 

    mytest("This is one of my own tests.") { 
    // ... 
    } 

    mytest("This is another test.") { 
    // ... 
    } 

    // ... 
} 

這就是說,有這裏沒有增值(尚未),和你需要付出很多努力來複制現有的功能。但是,您可以明確修改mytest的定義以執行您可能需要的一些樣板操作。