针对问题:springboot测试类中的@Autowired注解报空指针异常
解决方法:
首先在测试类上加上
@RunWith(SpringRunner.class)
@SpringBootTest(classes = 你的springboot启动类名.class)
然后在测试方法上加上
@Test
示例
@RunWith(SpringRunner.class)
@SpringBootTest(classes = FiscoBcosServiceApplication.class)
public class BlockChainServiceImplPlusTest extends TestCase {
@Autowired
BlockChainServiceImpl bcsp;
@Test
public void testRegister() {
bcsp.register("13212");
}
}