本文介绍了使用 TestNG 进行 Spring 依赖注入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Spring 很好地支持 JUnit:使用 RunWithContextConfiguration 注释,事情看起来非常直观

Spring support JUnit quite well on that:With the RunWith and ContextConfiguration annotation, things look very intuitive

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:dao-context.xml")

此测试将能够在 Eclipse & 中运行.Maven 正确.我想知道TestNG是否有类似的东西.我正在考虑转向这个下一代"框架,但我没有找到适合使用 Spring 进行测试的匹配项.

This test will be able to run both in Eclipse & Maven in correctly.I wonder if there is similar stuff for TestNG. I'm considering moving to this "Next Generation" Framework but I didn't find a match for testing with Spring.

推荐答案

它也适用于 TestNG.您的测试类需要扩展以下类之一:

It works with TestNG as well. Your test class needs to extend one of the following classes:

这篇关于使用 TestNG 进行 Spring 依赖注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 16:52
查看更多