The test class below looks fine at first glance, but after running it, it keeps showing that ZsxqApi
has not been injected and is null
@SpringBootTest
public class AppTest {
@Value("${ChatBot-api.groupId}")
private String groupId;
@Value("${ChatBot-api.cookie}")
private String cookie;
@Autowired
private ZsxqApi zsxqApi;
@Test
public void Test() throws IOException {
zsxqApi.getWithoutCommentsTopics(groupId, cookie);
}
}
Solution#
Add
@RunWith(SpringRunner.class)
: Indicates that during testing, dependency injection and other functionalities can be performed
@RunWith(SpringRunner.class)
@SpringBootTest
public class AppTest {
……
}