Idea 中 如果加载scalatest的jar包后,一切顺利,当你写下如下代码的时候,会提示你no implicits found for parameter pos在test(){..}(这里报错)
。查了各种资料都没有怎么填pos这个位置的方法。且示例都不用写pos。
例如如下示例是可以运行的:
import org.scalatest.funsuite
class MyTest extends funsuite.AnyFunSuite {
val s = "a b c d"
test("长度大于4"){
assert(s.length > 4)
}
}
报错原因
新建的是scala工程,仅导入一个scalatest-funsuite_2.11-3.2.0.jar的包是不够的,还要导入scalatest-compatible-3.2.0.jar和scalatest-core_2.11-3.2.0.jar包。这样才有pos的隐式转换能力。
更简单的方法
改建scala的pom工程,然后加如下依赖即可,工程会自动加载funsuite,core,compatible 包
<dependencies>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-funsuite_2.11</artifactId>
<version>3.2.0</version>
<scope>test</scope>
</dependency>
</dependencies>