【问题标题】:Testing an injected config with spring without spring test runner在没有弹簧测试运行器的情况下使用弹簧测试注入的配置
【发布时间】:2014-03-14 08:12:56
【问题描述】:

给定以下类:

公共类 ClassToBeTest{

${property.utility}

私有字符串属性;

私人实用工具;

public ClassToBeTested(实用工具){

this.utility = 实用程序;

}

public void doSomething(){

utility.doSomething(property);

}

}

我们想要模拟 Utility(例如,我们正在使用 Mockito)并验证是否调用了实用程序.doSomething,并传递了属性参数。

我们并不真正关心配置值(我们有其他测试)。但是我们不想用类似的方法打开类(或通过构造函数传递属性)。

public void setPropertyForTest(String property){

this.property = 属性;

}

有没有其他方法可以检查这个私有属性(没有值)是否传递给了 Utility?

非常感谢。

【问题讨论】:

    标签: testing spring-test


    【解决方案1】:

    如果你只想设置private 字段,Spring(不是Sprint)在spring-test 模块中提供了支持。查看ReflectionTestUtils 中的setField() 变体。

    问候,

    山姆

    【讨论】:

    • 敏捷对我造成了如此大的伤害:)
    猜你喜欢
    • 2011-11-27
    • 1970-01-01
    • 1970-01-01
    • 2016-12-13
    • 2012-11-02
    • 2016-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多