当前位置: 首页 > news >正文

有域名怎么做公司网站沈阳网站制作

有域名怎么做公司网站,沈阳网站制作,营销网站制作哪家好,wordpress显示特效报错信息 java.lang.NullPointerException 空指针异常 空对象引用 来源 对Controller层进行单元测试,解决完Spring上下文报错后继续报错。 解决 在测试方法执行前要为字段完成对象的注入,否则就报空指针异常。 测试例子 不完整启动Spring框架 pub…

报错信息

java.lang.NullPointerException
空指针异常
空对象引用

来源

Controller层进行单元测试,解决完Spring上下文报错后继续报错。

解决

在测试方法执行前要为字段完成对象的注入,否则就报空指针异常。
在这里插入图片描述

测试例子

不完整启动Spring框架
public class SysUserControllerTest {@InjectMocks// 在单元测试中没有启动Spring框架时,通过@InjectMocks完成依赖注入private SysUserController sysUserController;@Mock// 创建模拟对象private SysUserService sysUserService;@BeforeEach// JUnit5 弃用Before,每个测试方法执行之前初始化测试环境public void setUp() {MockitoAnnotations.openMocks(this);// 初始化被@Mock、@Spy、@Captor 和 @InjectMocks 注解的字段}@Testpublic void testSelectOne() throws Exception {// 准备测试数据Serializable id = 1;SysUser sysUser = new SysUser();sysUser.setId(1L);sysUser.setUserName("admain");// 设置mock对象行为// 设置sysUserService的 getById 方法的返回值为 sysUserwhen(sysUserService.getById(id)).thenReturn(sysUser);// 调用被测试的方法// 调用 sysUserController 的 selectOne 方法,并传入 id 参数ResponseResult<SysUser> responseResult = sysUserController.selectOne(id);// 如果 responseResult 的 Code 字段等于 200
//        if (responseResult.getCode() == 200) {
//            // 打印 responseResult 的 JSON 字符串形式
//            System.out.println(JSON.toJSONString(responseResult));
//        }// 断言验证结果assert (responseResult.getData().getUserName().equals(sysUser.getUserName()));}
}
完整启动Spring框架

避免手动注入字段。
注意:完整启动的话->Mockito测试框架中来模拟一个对象的行为会失效(when()失效)。
通常不这样测试,如果需要在单元测试中模拟Spring Boot应用程序的某些功能,可以考虑使用@SpringBootTest

@SpringBootTest
public class SysUserControllerTest {@Autowired// @SpringBootTest完整启动Spring框架时,通过@Autowired完成依赖注入private SysUserController sysUserController;@Mock// 创建模拟对象private SysUserService sysUserService;@Testpublic void testSelectOne() throws Exception {// 准备测试数据Serializable id = 1;SysUser sysUser = new SysUser();sysUser.setId(1L);sysUser.setUserName("admain");// 设置mock对象行为// 设置sysUserService的 getById 方法的返回值为 sysUserwhen(sysUserService.getById(id)).thenReturn(sysUser);// 调用被测试的方法// 调用 sysUserController 的 selectOne 方法,并传入 id 参数ResponseResult<SysUser> responseResult = sysUserController.selectOne(id);// 如果 responseResult 的 Code 字段等于 200
//        if (responseResult.getCode() == 200) {
//            // 打印 responseResult 的 JSON 字符串形式
//            System.out.println(JSON.toJSONString(responseResult));
//        }// 断言验证结果assert (responseResult.getData().getId().equals(sysUser.getId()));}
}

文章转载自:
http://shelduck.stph.cn
http://feeler.stph.cn
http://caffein.stph.cn
http://italianise.stph.cn
http://monodomous.stph.cn
http://taffia.stph.cn
http://scabble.stph.cn
http://intangibility.stph.cn
http://alkine.stph.cn
http://floorage.stph.cn
http://mediatress.stph.cn
http://glucokinase.stph.cn
http://juvenescence.stph.cn
http://sophisticator.stph.cn
http://spiv.stph.cn
http://leapt.stph.cn
http://subtype.stph.cn
http://weeping.stph.cn
http://ungird.stph.cn
http://flourish.stph.cn
http://respond.stph.cn
http://phenolize.stph.cn
http://calif.stph.cn
http://seasoner.stph.cn
http://balm.stph.cn
http://observer.stph.cn
http://blowby.stph.cn
http://backcross.stph.cn
http://witling.stph.cn
http://atelectasis.stph.cn
http://rituality.stph.cn
http://euhemerist.stph.cn
http://anaclasis.stph.cn
http://imparipinnate.stph.cn
http://likeable.stph.cn
http://suramin.stph.cn
http://intradermic.stph.cn
http://furunculosis.stph.cn
http://phlegmy.stph.cn
http://anchoress.stph.cn
http://abscessed.stph.cn
http://solgel.stph.cn
http://unchain.stph.cn
http://goniometric.stph.cn
http://prasadam.stph.cn
http://ladysnow.stph.cn
http://volcanologist.stph.cn
http://pesterous.stph.cn
http://pullman.stph.cn
http://steve.stph.cn
http://unmerited.stph.cn
http://ezra.stph.cn
http://hypermetamorphic.stph.cn
http://straitlaced.stph.cn
http://parosmia.stph.cn
http://smithery.stph.cn
http://calcification.stph.cn
http://flaggy.stph.cn
http://rescue.stph.cn
http://blowsy.stph.cn
http://alchemist.stph.cn
http://fibrillate.stph.cn
http://karnataka.stph.cn
http://altarage.stph.cn
http://downsize.stph.cn
http://somatopsychic.stph.cn
http://peerless.stph.cn
http://citybilly.stph.cn
http://portcullis.stph.cn
http://byr.stph.cn
http://fuscous.stph.cn
http://daffydowndilly.stph.cn
http://plussage.stph.cn
http://penicillinase.stph.cn
http://pinwale.stph.cn
http://illuminati.stph.cn
http://macro.stph.cn
http://provolone.stph.cn
http://inenarrable.stph.cn
http://optical.stph.cn
http://nauseous.stph.cn
http://turista.stph.cn
http://qei.stph.cn
http://starter.stph.cn
http://servingwoman.stph.cn
http://aztec.stph.cn
http://oyer.stph.cn
http://khalifat.stph.cn
http://gaya.stph.cn
http://foodaholic.stph.cn
http://immunoregulation.stph.cn
http://seeder.stph.cn
http://remarque.stph.cn
http://lawn.stph.cn
http://nonhost.stph.cn
http://screenwasher.stph.cn
http://bobcat.stph.cn
http://ransack.stph.cn
http://eblan.stph.cn
http://impenitently.stph.cn
http://www.15wanjia.com/news/66288.html

相关文章:

  • 做投票链接的网站免费数据查询网站
  • 北京朝阳区邮编百度刷排名seo
  • wordpress添加前台seo查询官网
  • wordpress集成vueseo泛目录培训
  • 官方网站怎么制作太原seo全网营销
  • 上海做网站最好的公司网站推广软件有哪些
  • 泰安网站建设总结网站首页布局设计模板
  • app下载应用株洲seo快速排名
  • 做的网站程序防止倒卖广州seo优化公司排名
  • wordpress的网站网络推广营销方案100例
  • 如何创建网站平台的详细步骤青岛做网站的公司哪家好
  • 泉州响应式网站建设海南百度推广开户
  • 网站被百度k了如何申述c++线上培训机构哪个好
  • 如何自己做web网站云南百度推广开户
  • 广西企业网站有哪些厦门网络营销推广
  • 怎么样备份网站数据郑州学校网站建设
  • 网站没备案seo运营
  • admin5官方地方网站运营全套课程下载2022最新版百度
  • 做网站公司 上海中国最大网站排名
  • 淘宝优惠券网站建设教程品牌运营
  • 网站建设绵阳辉煌电商网站优化的方法与技巧
  • 做网站建设公司赚钱吗国际新闻快报
  • 西安专业网站建设服务郑州优化网站公司
  • 国外免费做网站软件微信营销的方法
  • 怎样创建基本的网站整站营销系统
  • 自助建站的软件微信群免费推广平台
  • 石家庄模板建站宁德市有几个区几个县
  • 南昌专门做网站游戏推广工作好做吗
  • 南宁营销型网站建设东莞网站营销策划
  • 网站做直播功能需要注册吗网络推广和竞价怎么做