写单元测试遇到下面的问题
BaseTest 中的producer 已经存在值了再次被赋值导致系统异常
org.springframework.beans.factory.BeanCreationException:
Could not inject field: protected mq.producer.Producer BaseTest.producer; nested exception is java.lang.IllegalStateException: The field protected mq.producer.Producer BaseTest.producer cannot have an existing value

mock赋值
org.springframework.boot.test.mock.mockito.MockitoPostProcessor#inject(java.lang.reflect.Field, java.lang.Object, java.lang.String)

 private void inject(Field field, Object target, String beanName) {try {field.setAccessible(true);Assert.state(ReflectionUtils.getField(field, target) == null,() -> "The field " + field + " cannot have an existing value");Object bean = this.beanFactory.getBean(beanName, field.getType());ReflectionUtils.setField(field, target, bean);}catch (Throwable ex) {throw new BeanCreationException("Could not inject field: " + field, ex);}}

出现问题的原因是 我的单元测试使用了

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Application.class)
@RunWith(JMockit.class)

两种方式
在idea中执行文件夹的时候
在JUNIT执行中发现 当下面runners 中只有一个类的时候是没有任何问题的,多个runner复用的时候 可能会引发一系列的问题。后续类似奇怪的问题可以参考此方案查询
org.junit.runner.JUnitCore#run(org.junit.runner.Runner)

runner = {IdeaSuite48@2281} myName = "test"runners = {Collections$UnmodifiableRandomAccessList@2286}  size = 80 = {JMockit@2292} 1 = {SpringJUnit4ClassRunner@2293} 2 = {SpringJUnit4ClassRunner@2294} 3 = {SpringJUnit4ClassRunner@2295} 4 = {SpringJUnit4ClassRunner@2296} 5 = {SpringJUnit4ClassRunner@2297} 6 = {SpringJUnit4ClassRunner@2298} 7 = {SpringJUnit4ClassRunner@2299} childrenLock = {Object@2287} testClass = {TestClass@2288} filteredChildren = {Collections$UnmodifiableCollection@2289}  size = 8scheduler = {ParentRunner$1@2290}

依赖包

     <dependency><groupId>org.jmockit</groupId><artifactId>jmockit</artifactId><version>1.8</version><scope>test</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><version>2.1.2.RELEASE</version><scope>test</scope></dependency>

使用下面的注解就也么有问题

@RunWith(MockitoJUnitRunner.Silent.class)
     <dependency><groupId>org.mockito</groupId><artifactId>mockito-core</artifactId><version>2.21.0</version><scope>test</scope></dependency>

cannot have an existing value相关推荐

  1. conflicts with existing, non-compatible bean definition of same name and class

    Annotation-specified bean name 'xxxxxImpl' for bean class [cn.abc.dao.service.xxxxxImpl] conflicts w ...

  2. SAP WM中阶之存储类型上架策略I(Adding to existing stock)

    SAP WM中阶之存储类型上架策略I(Adding to existing stock) SAP WM模块里,有很多上架策略.Adding to existing stock是一种常用的上架策略.这种 ...

  3. python paramiko包 ssh报错No existing session 解决方法

    在connect 的时候加入参数 allow_agent, look_for_keys 就可以了 ssh.connect('localhost',username=name,password=pw,a ...

  4. 在linux上安装cuda的时候报错:Existing package manager installation of the driver found.

    文章目录: 1 错误原因 2 解决方法 1 错误原因 安装cuda的时候提示有多个显卡驱动:Existing package manager installation of the driver fo ...

  5. 【Laravel】There is no existing directory at “…/storage/logs” and its not buildable: Permission denied

    There is no existing directory at "-/storage/logs" and its not buildable: Permission denie ...

  6. 【若依(ruoyi)】启动时,卡死在:Using existing EHCache named [loginRecordCache]

    前言 ruoyi 4.6.0 现象 . ____ _ __ _ _/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ ...

  7. How to extend unallocated space to an existing partition on linux? | 如何在 linux 上扩展已有分区至未分配空间?

    How to extend unallocated space to an existing partition on linux? 背景:我这台机器上(多重启动)装了三个系统,windows + a ...

  8. The proctime attribute ‘rowtime‘ must not replace an existing field.

    故障代碼如下: // ************************************************************************* // USER DATA TY ...

  9. 23 WM配置-策略-入库策略3-定义现有库存的附加策略I(Addition to Existing Stock Strategy)

    业务背景:入库策略之3 定义现有库存的附加策略 就是Addition to Existing Stock Strategy.将入库的上架库存数量增加到现有的仓位中,这就需要系统寻找到相同的物料编号的库 ...

  10. 【Paper-Attack】Attacking Graph-Based Classification without Changing Existing Connections

    Attacking Graph-Based Classification without Changing Existing Connections 背景 training dataset中包含pos ...

最新文章

  1. 7个IntelliJ IDEA必备插件,让写代码像火箭一样飞起!
  2. sqlalchemy 对 mysql 进行增删改查
  3. Fescar 全局锁介绍
  4. always中的敏感变量
  5. [Android实例] 【eoeAndroid社区索引】android开发基础之定位篇
  6. 如何恢复MAC苹果电脑系统数据文件恢复详细教程
  7. 树莓派链接USB摄像头
  8. linux ftp prompt off,FTP命令详解及使用技巧
  9. 1050: 找出直系亲属
  10. 自媒体人绝对要知道的6款软件工具!免费文案、配音不在话下
  11. python数据分析之《太平洋汽车》点评数据及论坛文本分析
  12. libnetwork
  13. .npy文件的打开方式
  14. 【C4-AI大赛】2021优秀作品荟
  15. 动网8.2版本的注入漏洞的利用
  16. 如何在ST官网和keil官网下载相关资料(外设库和芯片器件库)
  17. Mac 新系统安装CocoaPods
  18. 嵌入式学习记录(1)——四足蜘蛛机器人
  19. Windows编程的图形基础(一)HDC, HPEN, HBRUSH
  20. 去中心化身份(Decentralized Identity)

热门文章

  1. antd 嵌套表格 没有子项隐藏图标
  2. 光端机2m是什么意思,光端机E1与2M有什么关系?
  3. 给discuz x增加后台菜单管理功能
  4. 内存虚拟化EPT技术简介
  5. matlab导数曲线怎样画,matlab三次样条曲线的绘制(spline和csape函数详解)
  6. 阿玛机器人_豪华日本声优阵容,《战斗天赋解析系统》让你耳朵怀孕!
  7. 电子计算机司法鉴定客体特征,电子证据司法鉴定的含义和特点是什么?
  8. web前端期末大作业:基于HTML+CSS+JavaScript奥迪企业bootstrap响应式网站
  9. ElementUI 整体页面布局
  10. 全局阙值分割中的直方图算法和熵算法