Scala Cats 使用 mockito-scala-cats 监视一个方法
Scala Cats spy a method with mockito-scala-cats
我正在尝试使用 mockito-scala-cats 模拟一个方法
例如
这是我的class
class MyService {
def getProperty(property: String): Either[Future, String, ExternalUser] = ???
}
和测试class
class MyServiceSpec extends FunSpec with MockitoSugar with MockitoCats {
describe("MyServiceApiImpl") {
it("get property") {
val serviceApi = mock[MyService]
whenF(serviceApi.getProperty("name")) thenReturn UserExternal()
}
}
}
我明白了
could not find implicit value for parameter a: cats.Applicative[[B]cats.data.EitherT[scala.concurrent.Future,String,B]]
检查您的导入。以下代码为我编译
import org.mockito.MockitoSugar
import org.mockito.cats.MockitoCats
import org.scalatest.FunSpec
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global // check this import
import cats.data.EitherT
import cats.instances.future._ // and this import
class MyService {
def getProperty(property: String): EitherT[Future, String, ExternalUser] = ???
}
class MyServiceSpec extends FunSpec with MockitoSugar with MockitoCats {
describe("MyServiceApiImpl") {
it("get property") {
val serviceApi = mock[MyService]
whenF(serviceApi.getProperty("name")) thenReturn ExternalUser()
}
}
}
case class ExternalUser()
我正在尝试使用 mockito-scala-cats 模拟一个方法
例如
这是我的class
class MyService {
def getProperty(property: String): Either[Future, String, ExternalUser] = ???
}
和测试class
class MyServiceSpec extends FunSpec with MockitoSugar with MockitoCats {
describe("MyServiceApiImpl") {
it("get property") {
val serviceApi = mock[MyService]
whenF(serviceApi.getProperty("name")) thenReturn UserExternal()
}
}
}
我明白了
could not find implicit value for parameter a: cats.Applicative[[B]cats.data.EitherT[scala.concurrent.Future,String,B]]
检查您的导入。以下代码为我编译
import org.mockito.MockitoSugar
import org.mockito.cats.MockitoCats
import org.scalatest.FunSpec
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global // check this import
import cats.data.EitherT
import cats.instances.future._ // and this import
class MyService {
def getProperty(property: String): EitherT[Future, String, ExternalUser] = ???
}
class MyServiceSpec extends FunSpec with MockitoSugar with MockitoCats {
describe("MyServiceApiImpl") {
it("get property") {
val serviceApi = mock[MyService]
whenF(serviceApi.getProperty("name")) thenReturn ExternalUser()
}
}
}
case class ExternalUser()