I am using nested classes for writing unit test cases in spring boot. My test case file is :
@RunWith(NestedRunner.class)
@SpringBootTest
@TestInstance
@AutoConfigureMockMvc
public class OuterTestCase {
public static class InnerTestCases {
@Autowired
private RestTemplate restTemplate;
@Autowired
private MockMvc mockMvc;
@Test
public void testcase(){
//do Something
}
}
}
But I am getting NPE when tried using RestTemplate inside testCase method.
I am unable to initialize beans inside the inner class.
A static class gets initialized during early stages of class loading. Unless the Autowired class has been initialized using a static class you will encounter above error.