尝试学习一些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 [error] val awsProvider = new AwsProvider(awsAccountId,awsAccountSecret)[错误]
从错误消息中看起来它看到一个零参数的构造函数?
谁能看到我在这里做错了什么?
答案 0 :(得分:2)
这是一个典型的菜鸟错误。我修复了我的测试类名称,因为使用相同的名称会影响原始名称,因此我实际测试了我的测试类:
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)
}
}
现在它过去了。