构造函数的参数太多
Too many arguments for constructor
正在尝试学习一些 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]
从错误消息来看,它似乎看到了一个参数为零的构造函数?
谁能看出我做错了什么?
这是一个典型的菜鸟错误。我修复了我的 test-class' 名称,因为使用相同的名称会影响原始名称,因此我实际上是在测试我的测试 class:
package com.fluentaws
import org.scalatest._
class AwsProviderTestSuite 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)
}
}
现在它过去了。
正在尝试学习一些 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]
从错误消息来看,它似乎看到了一个参数为零的构造函数?
谁能看出我做错了什么?
这是一个典型的菜鸟错误。我修复了我的 test-class' 名称,因为使用相同的名称会影响原始名称,因此我实际上是在测试我的测试 class:
package com.fluentaws
import org.scalatest._
class AwsProviderTestSuite 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)
}
}
现在它过去了。