次のようなコントローラーがあります。
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 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
}