Reputation: 21
I am unable to access an autowired class (ListService) located in a test class. Outside of the test, I can successfully access the autowired class to make the following call:
List schoolSubjectList = listService.getMathSubjectList();
The above call results in a null pointer exception.
Test Class:
...
@Autowired
ListService listService;
@BeforeClass
public void setUp(ITestContext context) throws Exception {
Random random = new Random();
int randomInteger = Math.abs(random.nextInt(1000));
suiteParams = context.getSuite().getXmlSuite().getAllParameters();
List<SchoolSubjectDto> schoolSubjectList = listService.getMathSubjectList();
int sizeOfSchoolSubjectList = schoolSubjectList.size();
...
Upvotes: 2
Views: 3332
Reputation: 1327
Make sure your class implements AbstractTransactionalTestNGSpringContextTests
.
For a full example, see mkyong.com/unittest/testng-spring-integration-example
Upvotes: 5