【发布时间】:2019-04-26 20:56:57
【问题描述】:
我有“服务”类,我需要测试它的方法。我不明白如何从测试中访问“Service”类的方法。
我试过这样做:
package services
import scala.concurrent.{ExecutionContext, Future}
import com.google.inject.Inject
import models.{News, State}
import org.scalatest.{MustMatchers, WordSpec}
class NewsServiceTest @Inject()(
newsService: NewsService
)(implicit val ec: ExecutionContext) extends WordSpec with MustMatchers {
"News controller" must {
"find all must return sequence with news-object" in {
val news = News(
id = 1,
title = "renamed test title 2",
short_title = Some("r t s t 2"),
text = "here is some text about my life and other beautiful things."
)
val result: Future[Seq[News]] = newsService.findAll(Some(State.Active))
result.map(a => a must contain (news))
}
}
}
但它不起作用
类服务
class NewsService @Inject()(newsDAO: NewsDAO)(implicit ec: ExecutionContext) {
def findAll(stateO: Option[State.Value]) = {
stateO.map(newsDAO.find).getOrElse(newsDAO.findAll)
}
def findOne(id: Long) = {
newsDAO.findOne(id).toEither(InternalDatabaseError.NotFound(classOf[News]))
}
def delete(id: Long) = {
newsDAO.delete(id)
}
//and other methods
}
【问题讨论】:
标签: scala playframework scalatest