gpt4 book ai didi

scala - 在 Scala 方法中自动委派给 val

转载 作者:行者123 更新时间:2023-12-01 09:06:59 25 4
gpt4 key购买 nike

我正在为 Wicket 应用编写 ScalaTest FeatureSpec。我有一个 wicketTester 值,我不得不继续调用方法,即:

scenario("No username and password") {
val wicketTester = new WicketTester(app)
given("user visits Admin home page")
wicketTester.startPage(classOf[AdminHomePage])

then("signin page is displayed")
val login = wicketTester.newFormTester("signInPanel:signInForm")
wicketTester.assertRenderedPage(classOf[SignInPage])
...
when("correct username and password are entered")
...
then("no login and error is displayed")
wicketTester.assertRenderedPage(classOf[SignInPage])
wicketTester.assertErrorMessages(Array("Field 'password' is required."))

现在所有这些对 wicketTester 的引用都让我失望,所以我想删除它们,以实现 DSL 必杀技...

scenario("No username and password") {
val wicketTester = new WicketTester(app)
given("user visits Admin home page")
startPage(classOf[AdminHomePage])

then("signin page is displayed")
val login = wicketTester.newFormTester("signInPanel:signInForm")
assertRenderedPage(classOf[SignInPage])...

有什么方法可以使本地方法看起来就像是我的类中的方法一样?

最佳答案

你试过导入吗?

scenario("No username and password") {
val wicketTester = new WicketTester(app)
import wicketTester._ // import wicketTester's members into scope
given("user visits Admin home page")
startPage(classOf[AdminHomePage])

then("signin page is displayed")
val login = wicketTester.newFormTester("signInPanel:signInForm")
assertRenderedPage(classOf[SignInPage])...
}

关于scala - 在 Scala 方法中自动委派给 val,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6283557/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com