0

我正在尝试使用 mockito-scala-cats 模拟一个方法

例如

这是我的课

class MyService {

  def getProperty(property: String): Either[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 UserExternal()
    }
  }

}

我明白了

找不到参数 a 的隐式值:cats.Applicative[[B]cats.data.EitherT[scala.concurrent.Future,String,B]]

4

1 回答 1

2

检查你的进口。以下代码为我编译

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()
于 2019-05-23T19:36:11.827 回答