2016-05-07 19 views
0

テストクラスにあるautowiredクラス(ListService)にアクセスできません。テストの外で、私は成功し、次の呼び出しにするautowiredクラスにアクセスすることができますAutowiredがTestNGテストクラスで動作しない

一覧をschoolSubjectList = listService.getMathSubjectList();

上記の呼び出しにより、NULLポインタ例外が発生します。

テストクラス:

... 
@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(); 

    ... 
+0

mkyong.com/unittest/testng-spring-integration-exampleを参照してください?それはオートワイヤリングを担当するでしょう。 –

+0

http://www.mkyong.com/unittest/testng-spring-integration-example/をご覧ください。素晴らしい例がありますか? –

+0

@AlexandreFillatreあなたの答えは私のために働いた。回答として投稿してください。それはコミュニティに役立つでしょう。 –

答えて

1

クラスがAbstractTransactionalTestNGSpringContextTestsを実装していることを確認します。フルたとえば

は、あなたのテストクラスは `AbstractTransactionalTestNGSpringContextTests`を実装してい

関連する問題