将 Spring 集成测试放在不同的类和包中
我正在使用 AbstractTransactionalSpringContextTests 来运行 spring 集成测试。 spring 上下文仅加载一次,然后运行所有测试。 如果我希望我的测试位于多个类和包中,我该如何做同样的事情。
当然,对于我的所有测试(在所有类和包中),spring 上下文应该只加载一次,而不是每个类或包加载一次。
I am using AbstractTransactionalSpringContextTests to run spring integrations tests.
The spring context is loaded just once and then all the tests are run.
How do I do the same if I want my tests to be in many classes and packages.
Of course, the spring context should be loaded just once for all my tests (in all classes and packages), and not once per class or package.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
作为
AbstractSingleSpringContextTests 的 Javadoc
(AbstractTransactionalSpringContextTests
的超类之一)状态:您的上下文已被缓存,因此在同一类加载器中运行的所有其他测试(即在同一测试运行期间运行的所有其他测试)将使用缓存的上下文。 您无需进行任何额外的设置 - 应该已经为您完成了。 如果您对此不确定,或者希望排除故障,只需打开 org.springframework 的日志记录,您应该会看到大量有关上下文加载时间、哪个文件、如何加载的有用日志记录; ETC。
As the Javadocs for
AbstractSingleSpringContextTests
(one of the superclasses ofAbstractTransactionalSpringContextTests
) state:Your context is cached, so all other tests that run within the same classloader (i.e. - all your other tests that run during the same test run) will use the cached context. You don't need to do any extra setup - should be done for you already. If you're not sure about this, or wish to troubleshoot, simply turn on the logging for org.springframework and you should see plenty of helpful logging about when the context is being loaded, which file, how; etc.