Question

I am testing a Scalatra servlet that does some important initialization in its init(context: ServletContext) method.

During tests (with ScalatraSuite) that init is not executed. How should I do my important initialization when I am testing?

That Scalatra testing page (section "Testing FAQ") does not reveal that.

Extra Info:
The "Testing FAQ" section states

scalatra-test is built on Jetty's [ServletTester][3]

but I also could not extract any information from the internet on how to run the init if I were coding in java.

Was it helpful?

Solution

You can use the servletContextHandler for those things in a test.

You can set initParameters with servletContextHandler.setInitParameter("the.param", "the.value")

I'll update the docs so they won't say that the testing support is added through jetty tester. In fact it uses an embedded jetty server so the init method should get called.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top