简体   繁体   English

在IntelliJ IDEA中使用Spring-test-mvc进行测试的更简单方法? 备择方案?

[英]Easier way to test with Spring-test-mvc in IntelliJ IDEA? Alternatives?

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. 我最近一直在尝试spring-test-mvc,因为当您像在Spring 3.0中那样传递对象时,在应用程序上下文中使用handlerAdapter和handlerMapping对象不再支持会话属性。

Is there any way to ease the coding of these tests from IntelliJ IDEA? 有什么方法可以简化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). 必须导入这么多静态方法非常耗时,并且说实话,我更喜欢使用我的旧方法进行更多测试(但是在3.1中我不能再这样做了)。 Is there any way to tell IntelliJ IDEA: "If I type get() , automatically import that method statically" ? 有什么办法告诉IntelliJ IDEA:“如果我键入get() ,则自动静态导入该方法”?

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? 除了控制器逻辑之外,spring-test-mvc是否有其他替代方法更容易编写代码,而且还能测试请求映射? 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. 除了在spring-test-mvc中编写测试的怪异语法之外,将会话属性传递到控制器中似乎真的很奇怪。 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 谢谢

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 * . 在IntelliJ的首选项中,在“ Project Settings > Code Style > Java下并在“ Import选项卡下,您可以输入始终要使用*导入的某些包。 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. 如果输入经常导入的spring-test-mvc类的软件包名称,则IntelliJ应该在开始键入时自动为您建议方法(并为其添加导入)。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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