没有 SpringJUnit4ClassRunner 或 AbstractJUnit4SpringContextTests 的 Spring 测试上下文设置(在 Selenium 测试中)
我正在使用 Selenium 1.x 和 Spring 3.0 设置 JUnit 4.7 测试。
我想扩展 Selenium 的 SeleneseTestCase
以获取它提供的快捷方式和约定(更重要的是,Selenium IDE 生成的代码似乎期望如此)。但我希望 Spring 上下文和其他优点能够在执行过程中出现。
因为我无法扩展 Spring 的 AbstractJUnit4SpringContextTests
,所以我尝试使用 @RunWith(SpringJUnit4ClassRunner.class)
来装饰我的测试用例。这成功地设置了 Spring,但在 Selenium 执行中导致了一些奇怪的情况:例如,测试执行缓慢并且浏览器窗口保持打开状态。我想它会覆盖 Selenium 的某些部分(只是猜测)...不幸的是,基本的 SeleneseTestCase 类只允许更改一组受限制的参数,例如设置执行速度(让我想知道,如果基类毕竟那么好......)。
据我了解,为了使 Spring 的所有功能正常工作,我必须扩展 AbstractJUnit4SpringContextTests
或使用 @RunWith(SpringJUnit4ClassRunner.class)
修饰该类。然而,前者我不能,后者带来问题。
只有 @ContextConfiguration
确实会加载上下文,但至少依赖注入不起作用。那是我停下来的地方。
如何使用 Selenium(或任何其他具有相同情况的库)巧妙地初始化 Spring?
编辑:使文本更具可读性。
I am setting up JUnit 4.7 tests with Selenium 1.x and Spring 3.0.
I want to extend Selenium's SeleneseTestCase
for the shortcuts and conventions it provides (more importantly, the Selenium IDE generated code seems to expect this). Yet I want the Spring context and other goodness to be present during the execution.
Because I cannot extend Spring's AbstractJUnit4SpringContextTests
, I tried decorating my test case with @RunWith(SpringJUnit4ClassRunner.class)
. This succesfully setups Spring but causes some oddities in Selenium execution: tests are executed slowly and browser windows are left open, for example. I suppose it overrides some part of Selenium (just a guess)... unfortunately, the base SeleneseTestCase
class only permits altering a restricted set of parameters, exluding setting the execution speed, for example (makes me wonder, if the base class is that nice after all...).
To my understanding, in order to make all the bells and whistles of Spring working, I must either extend the AbstractJUnit4SpringContextTests
or decorate the class with @RunWith(SpringJUnit4ClassRunner.class)
. However, the former I cannot, and the latter brings problems.
Having only @ContextConfiguration
does load up the context, but at least dependency injection is not working. That's where I stopped.
How can I initialize Spring neatly with Selenium (or any other library with same case)?
Edit: Made the text more readable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对类似的问题感到恼火,足以编写 一个 MethodRule 实现,该实现将加载 Spring 上下文并自动装配它的主机测试。也许这就是您正在寻找的东西的开始。
它将允许您执行以下操作:
如果您做出任何改进,请告诉我。
I was annoyed by a similar problem enough to write a MethodRule implementation that will load a Spring context and autowire it's host test. Maybe that is the start of what you're looking for.
It will allow you to do something like this:
If you make any improvements please let me know.