Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Dependency Injection with TestNG

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") 

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.

like image 811
Phương Nguyễn Avatar asked Apr 09 '10 15:04

Phương Nguyễn


1 Answers

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

  • org.springframework.test.context.testng.AbstractTestNGSpringContextTests
  • org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests
like image 54
lexicore Avatar answered Sep 22 '22 12:09

lexicore