简体   繁体   中英

Scalatra Servlet init() during test (Jetty ServletTester)

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM