My controller method:
def postCategory = Action(parse.tolerantText) { request =>
Ok("")
}
and this is my test:
val result = categoryController.postCategory.apply(FakeRequest())
status(result) mustEqual OK //error this line
I have this error:
Error:(63, 14) type mismatch; found : play.api.libs.streams.Accumulator[akka.util.ByteString,play.api.mvc.Result] required: scala.concurrent.Future[play.api.mvc.Result] status(result) mustEqual OK ^
It seem that using a custom parser parse.*
makes it returns Accumulator
rather than Future[Result]
I'm using play 2.5-RC2
Having parsed the input, the controller must transform the input into the model expected by the business logic and pass it on to the business logic. 5. The controller takes the output of the business logic and serializes it into an HTTP response. 6.
Test game controller input Connect your game controller to your PC. If you hear the installing hardware chime on Windows 10, allow drivers for it to install. Open your browser and visit Gamepad Tester. Press any button on the controller to wake it up. The controller will be detected by Gamepad ...
However, treat it as an Integration Test since you’re verifying several parts of your application. Don’t skip the Unit Test for the pure Controller layer if you need it. In other words, try to avoid mixing the test layers but rather keep them separate.
Custom Controller Testing Visualforce custom controller is required because custom controllers like all Apex codes, should be covered by unit tests. A custom controller is an Apex class that implements all of the logic for a page without leveraging a standard controller.
You do should use result.run getting instance of Materializer with Guice
would look like:
import akka.stream.Materializer
//...
def mockApp = new GuiceApplicationBuilder().build()
val mtrlzr = mockApp.injector.instanceOf[Materializer]
val result: Accumulator[ByteString, Result] = controller.accessToken()(FakeRequest())
val runResult: Future[Result] = result.run()(mtrlzr)
You can try with something like this:
val result = categoryController.postCategory.apply(FakeRequest())
status(result.run) must equalTo(OK)
It basically looks like Accumulator has a nice run()
method that returns a Future
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With