其他分享
首页 > 其他分享> > springboot单元测试 junit

springboot单元测试 junit

作者:互联网

@SpringBootTest
@RunWith(SpringRunner.class)//@RunWith(SpringRunner.class)这些类才能实例化到spring容器中,自动注入才能生效,不然会报异常
public class DictDaoTest extends TestCase {
    @Autowired
    private  DictDao dao;
    @Test
    public  void getByIdText(){
        Dict dict = dao.getById(1l);
        System.out.println("=================================="+dict);
    }
}

测试结果:

==================================Dict{type='sex', k='0', val='女'}

标签:RunWith,springboot,dao,单元测试,junit,SpringRunner,public,dict,class
来源: https://blog.csdn.net/weixin_55806809/article/details/121316357