0
試圖學習一些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)
}
}
當我的測試套件運行時,我得到的編譯時錯誤:
too many arguments for constructor AwsProvider: ()com.fluentaws.AwsProvider [error] val awsProvider = new AwsProvider(awsAccountId, awsAccountSecret) [error]
從錯誤消息,它看起來像它看到一個零參數的構造函數?
任何人都可以看到我在做什麼錯在這裏?
哦,..也許我正在重新定義一個名爲AwsProvider的新類,而不是擴展現有的類 – CodeMonkey
您應該重命名您的測試類。 – tkausl
是的,就是這樣:-) – CodeMonkey