banner
指数爆炸

指数爆炸

我做了对饭 !
github
bilibili

Don't forget to use `@RunWith(SpringRunner.class)` for dependency injection in test classes.

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 {
  ……
}
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.