简体   繁体   English

ReflectionTestUtils无法与MockitoJunitRunner一起使用

[英]ReflectionTestUtils not working with MockitoJunitRunner

Need is to write test case for a service. 需要的是为服务编写测试用例。 It initially uses value properties like : 最初使用值属性,例如:

@Value(#{"env.host"})
private String host;

I came across ReflectionTestUtils.setField and tried the same as below,with cloudImpl class with InjectMocks annotation: 我遇到了ReflectionTestUtils.setField并尝试了以下相同的操作,并使用带有InjectMocks批注的cloudImpl类:

ReflectionTestUtils.setField(cloudImpl, "env.host", "localhost");

All i get is cannot find field "env.host" of type null in cloudImpl class. 我得到的只是在cloudImpl类中找不到null类型的字段“ env.host”。 Could you please help figure out why ? 您能帮忙找出原因吗?

The field name is "host", not "env.host". 字段名称是“主机”,而不是“ env.host”。 So you should use 所以你应该使用

ReflectionTestUtils.setField(cloudImpl, "host", "localhost");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM