什么是AbstractTestNGSpringContextTests

问题描述 投票:8回答:2

我有一个TestNG类,如下所示:

public class WebAPITestCase extends AbstractTestNGSpringContextTests{.....}

我试图了解这意味着extends AbstractTestNGSpringContextTests

它是如何工作的以及它的用途是什么?

java spring unit-testing spring-mvc testng
2个回答
6
投票

请阅读javadoc:

抽象基本测试类,它将Spring TestContext Framework与TestNG环境中的显式ApplicationContext测试支持集成在一起。

基本上,将为测试类设置spring应用程序上下文。

如果那仍然没有意义,我建议你阅读Chapter 11 of Spring Manual on testing


0
投票

首先,TestNG(代表下一代测试)是一个受JUnit和NUnit启发的测试框架,但引入了一些新的功能,使其更强大,更易于使用,如测试,您的代码是多线程安全,强大的执行模型等。

课程AbstractTestNGSpringContextTests包括春天ApplicationContext。为了在执行TestNG测试时使其可用,AbstractTestNGSpringContextTests具有使用@BeforeClass@BeforeMethod等TestNG注释注释的方法。

因此,为了具有使用Spring组件运行TestNG的这一功能,剩下要做的就是扩展AbstractTestNGSpringContextTests

顺便说一句,AbstractTransactionalTestNGSpringContextTests延伸AbstractTestNGSpringContextTests。它不仅提供事务支持,还具有一些JDBC访问的便利功能。

© www.soinside.com 2019 - 2024. All rights reserved.