原始代码
package com.example.demo.service.Impl;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
/**
* @author XingShi
* @date 2021-03-31-16:09
*/
public class PayServiceImplTest{
@Autowired
private PayServiceImpl payService;
@Test
public void create() {
payService.create();
}
}
原因
经过仔细检查后,发现在测试类上忘记添加测试的有关注解==@SpringBootTest==、@RunWith(SpringRunner.class)。添加完注解后运行就没问题了