scala - How to test a controller in Play Framework with a functional test -
i'm trying make functional test controller play framework version 2.5.9.
i have controller called homecontroller
@singleton class homecontroller @inject()(implicit exec: executioncontext) extends controller { def index = action.async { future{ ok(views.html.index("home")) } } }
my view looks this
@(message: string) @main("home") { <h2>welcome</h2> }
the arguments in @main goes in title of page , test looks this
class applicationtwospec extends playspec oneserverpersuite onebrowserpersuite htmlunitfactory{ implicit val ec = implicits.global val homecontroller = new homecontroller() implicit override lazy val app = new guiceapplicationbuilder() .router(router.from{ case get(p"/") => homecontroller.index }) .build() "the sample controler server" must { "have home in title" in { go s"http://localhost:9000/" pagetitle mustbe "home" } } }
when run test back
must return , ok response *** failed *** "[]" not equal "[home]" (applicationtwospec.scala:37)
what need have yeild proper response?
i found problem after going source code of both scala test plus , playframework.
go s"http://localhost:9000/"
should
go s"http://localhost:$port/"
an implicit lazy val port
specified in oneserverpersuite
trait , gets default value play.api.test.helpers package defaults port 19001. if needed port 9000 override port using
implicit override lazy val port = 9000
Comments
Post a Comment