Pregunta

I've been recently trying out spring-test-mvc since using the handlerAdapter and handlerMapping objects in the application context no longer support session attributes when you pass objects in that way like they used to in Spring 3.0.

Is there any way to ease the coding of these tests from IntelliJ IDEA? Having to import so many static methods is rather time-consuming, and to be honest, I preferred my older method of testing a lot more (but I can no longer do it that way in 3.1). Is there any way to tell IntelliJ IDEA: "If I type get(), automatically import that method statically" ?

Are there any other alternatives to spring-test-mvc that are easier to code against but also test request mappings in addition to controller logic? I also need to support session attributes.

In addition to the weird syntax of writing tests in spring-test-mvc, it seems really odd to pass in session attributes into the controller. They seem to encourage creating an object constructor where you pass the session objects in that way... but I don't want to make this constructor on my controllers when it is not used during production. That's gotta be a testing anti-pattern, but I don't see any other way to pass in a session object as part of the request and their examples encourage making this object constructor.

Thanks

¿Fue útil?

Solución

In IntelliJ's preferences, under Project Settings > Code Style > Java and under the Import tab, you can enter certain packages you always want to import with *. If you enter the package names of the spring-test-mvc classes you are frequently importing, then IntelliJ should suggest (and add the import for) the methods for you automatically as you start typing.

enter image description here

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top