【发布时间】:2017-04-04 07:31:24
【问题描述】:
尝试学习一些 Scala。
我的项目中有以下类:
package com.fluentaws
class AwsProvider(val accountId: String, val accountSecret: String) {
def AwsAccount = new AwsAccount(accountId, accountSecret)
}
class AwsAccount(val accountId : String, val accountSecret : String) {
}
还有以下测试:
package com.fluentaws
import org.scalatest._
class AwsProvider extends FunSuite {
test("When providing AwsProvider with AWS Credentials we can retrieve an AwsAccount with the same values") {
val awsAccountId = "abc"
val awsAccountSecret = "secret"
val awsProvider = new AwsProvider(awsAccountId, awsAccountSecret)
val awsAccount = awsProvider.AwsAccount
assert(awsAccount.accountId == awsAccountId)
assert(awsAccount.accountSecret == awsAccountSecret)
}
}
当我的测试套件运行时,我收到编译时错误:
构造函数 AwsProvider 的参数过多: ()com.fluentaws.AwsProvider [错误] val awsProvider = new AwsProvider(awsAccountId, awsAccountSecret) [错误]
从错误消息看来,它看到了一个零参数的构造函数?
谁能看到我在这里做错了什么?
【问题讨论】:
-
哦,.. 也许我正在重新定义一个名为 AwsProvider 的新类,而不是扩展现有的类
-
你应该重命名你的测试类。
-
是的,就是这样:-)
标签: scala constructor tdd classname