如何为 Junits 模拟 applog
How to mock applog for Junits
实际上我正在为 class 使用 @Autowired AppLog
编写 junits 。
并且使用 this.applog.logInfo("field",+object.getFieldName())
,他们正在尝试打印值。
我不知道如何模拟这个东西。
我已经在使用 @RunWith(SpringRunner.class)
。
powerMock 在这种情况下可以提供帮助吗?如果有人能提供帮助,我将不胜感激。
在 Spring 中,我们有一个称为 [ReflectionTestUtils][1]
的 class,如果您正在测试具有依赖关系的 class,可以使用它。在这种情况下,因为我们有 applog 自动装配。
所以,我们在@Before
注解方法下可以定义:
ReflectionTestUtils.setField(instanceOfClassWeAreTesting,"appLog",mockedApplogInstance)
.
希望对以后遇到任何问题的人有所帮助。
实际上我正在为 class 使用 @Autowired AppLog
编写 junits 。
并且使用 this.applog.logInfo("field",+object.getFieldName())
,他们正在尝试打印值。
我不知道如何模拟这个东西。
我已经在使用 @RunWith(SpringRunner.class)
。
powerMock 在这种情况下可以提供帮助吗?如果有人能提供帮助,我将不胜感激。
在 Spring 中,我们有一个称为 [ReflectionTestUtils][1]
的 class,如果您正在测试具有依赖关系的 class,可以使用它。在这种情况下,因为我们有 applog 自动装配。
所以,我们在@Before
注解方法下可以定义:
ReflectionTestUtils.setField(instanceOfClassWeAreTesting,"appLog",mockedApplogInstance)
.
希望对以后遇到任何问题的人有所帮助。