Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is AbstractTestNGSpringContextTests

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?

like image 255
Java Questions Avatar asked Apr 05 '13 05:04

Java Questions


2 Answers

Please read the javadoc:

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.

like image 108
gerrytan Avatar answered Sep 27 '22 00:09

gerrytan


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.

like image 45
elirandav Avatar answered Sep 24 '22 00:09

elirandav