SpringBoot集成测试-存储库null

时间:2019-03-01 17:26:45

标签: spring spring-boot integration-testing

我有一个综合测试班 如下

@RunWith(SpringRunner.class)
@SpringBootTest(classes=LSchedulersApplication.class)
@DataJpaTest
@AutoConfigureTestDatabase(replace =Replace.NONE)
public class LSchedulersApplicationTests {

    @Autowired
    private WorkgroupRepository workgroupRepo;
    @Autowired
    private SignalRepository signalRepo;

//this works
    @Test
    public void test() {

        Iterable<Werkgroup> workgroupIterable = workgroupRepo.findAll();

        assertThat(((Collection<?>) workgroupIterable), not(IsEmptyCollection.empty()));
    }


//this fails with repositories as null
    @Test
    public void executeSignalPoller() throws JobExecutionException{
        SignalPoller poller = new SignalPoller();
        poller.execute(null);
    }
}

源类,它是一个石英作业[这只是石英,不是弹簧石英包装]

public class SignalPoller implements Job
{
    @Autowired
    private WorkgroupRepository workgroupRepo;
    @Autowired
    private SignalRepository signalRepo;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        somemethod();
..
    }
    private void somemethod(){
        ***blahblahblah*** = workgroupRepo.findAll();// NULL POINTER EXCEPTION
    }

}

我可以问什么遗漏吗? [我为源类添加了@Component批注,但没有解决]。

0 个答案:

没有答案