java 为@Value编写测试用例[已关闭]

e3bfsja2  于 2022-12-02  发布在  Java
关注(0)|答案(1)|浏览(166)

Closed. This question needs details or clarity . It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post .

Closed 16 hours ago.
Improve this question
How to write test cases for @Value variables?
I am trying to write test cases for a method which has an String array which is initialized using @Value.
And when I am writing test case for the same method I am getting an nullpointerexception.
Which is the right way to write test cases for such types?

bhmjp9jg

bhmjp9jg1#

您可以在模拟对象中注入org.springframework.test.util.ReflectionTestUtils的价值

ReflectionTestUtils.setField(
   serviceMocked, 
  "attrWithValueAnnotation",  // name attr in service
   valueaTobeInjectWhenTesting
);

相关问题