mashupbots / socko

A Scala web server powered by Netty networking and AKKA processing.
Other
255 stars 51 forks source link

Feature Request: Easy Testing Hooks #53

Closed pr1001 closed 11 years ago

pr1001 commented 11 years ago

I'm quite stumped how to test my Socko app, particularly if I want to make a request and test that the response returned from event.response.write() is correct. Would it be possible to add some functionality to Socko to make such testing easier?

veebs commented 11 years ago

Hi,

To test the output from event.response.write(), I just startup the web server and start sending HTTP requests at it.

I've written Socko tests using this strategy. See https://github.com/mashupbots/socko/tree/master/socko-webserver/src/test/scala/org/mashupbots/socko/handlers.

I've got a trait called TestHttpClient that I add to my test cases. For usage, see StaticContentSpec.scala and SnoopSpec.scala.

If I have a larger scale application, I would typically have a set of actors for my business rules that is not Socko aware. I would test these in the normal Akka way. I would then add a set of Socko HTTP aware actors that is a facade for the business rules actors. I would test the Socko HTTP aware actors using the TestHttpClient strategy mentioned above.

Hope this helps.

pr1001 commented 11 years ago

Thanks, I later found those tests and went that route. It will still be nice to be able to test at the HttpRequestEvent level, though. I having an intermediate actor like you describe is the best solution for now.