添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
越狱的茶叶  ·  MySQL:SELECT COUNT 小结 ...·  1 年前    · 
腹黑的蚂蚁  ·  【Uni-App】page.json ...·  2 年前    · 
很酷的跑步机  ·  探究Presto ...·  2 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have a TestNG class which is like the following:

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

I was trying to understand what this means extends AbstractTestNGSpringContextTests.

How does it work and what is the use of it?

AbstractTestNGSpringContextTests is an abstract base test class that integrates the Spring TestContext Framework with explicit ApplicationContext testing support in a TestNG environment. When you extend AbstractTestNGSpringContextTests, you can access a protected applicationContext instance variable that you can use to perform explicit bean lookups or to test the state of the context as a whole.

Basically a spring application context will be setup for the test class.

If that still doesn't make sense I'd recommend you read this.

First, TestNG (stands for Test Next Generation) is a testing framework inspired from JUnit and NUnit but introducing some new functionalities that make it more powerful and easier to use like test that your code is multithread safe, powerful execution model, etc.

The class AbstractTestNGSpringContextTests includes the spring ApplicationContext. To make it available when executing TestNG test, AbstractTestNGSpringContextTests has methods annotated with TestNG annotations like @BeforeClass and @BeforeMethod.

So to have this functionality of running TestNG with Spring components, all it left to do is to extend AbstractTestNGSpringContextTests.

BTW, AbstractTransactionalTestNGSpringContextTests extends AbstractTestNGSpringContextTests. It not only provides transactional support but also has some convenience functionality for JDBC access.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.