如何在单元测试中将配置对象传递给控制器

How to pass Configuration object to controller in unit test

我有一个控制器如下:

class MyController @Inject()
(
  cc : ControllerComponents,
) extends AbstractController(cc) with I18Support(

  def controllerMethod() = Action{
   ... //some impl.
  }
)

我正在我的 Scalatest 中测试我的控制器,如下所示:

"My Controller" when {

  "a user hits this controller method" should {

  val controller = new MyController( cc = stubMessageControllerComponents )

  "be a 200 OK" in {
    whenReady(controller.mycontrollerMethod().apply(FakeRequest("GET", "/"))) {
    // some test

   }

我的问题是现在我已经更改了控制器 class 以如下注入配置对象

class MyController @Inject()
(
  config : Configuration,
  cc : ControllerComponents,
) extends AbstractController(cc) with I18Support(

  def controllerMethod() = Action{
   ... //some impl.
  }
)

我现在在测试中遇到编译错误,因为我没有传入 Configuration 对象。我该怎么做?

"My Controller" when {

  "a user hits this controller method" should {

  val controller = new MyController(
    // <- how can I pass a configuration object here 
    cc = stubMessageControllerComponents 
  )

  "be a 200 OK" in {
    whenReady(controller.mycontrollerMethod().apply(FakeRequest("GET", "/"))) {
    // some test

   }

尝试

new MyController(
  config = Configuration(ConfigFactory.load()) 
  cc = stubMessageControllerComponents 
)