Reputation: 7963
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?
Upvotes: 15
Views: 13374
Reputation: 41143
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.
Upvotes: 10
Reputation: 2073
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.
Upvotes: 3