【发布时间】:2012-02-13 22:02:22
【问题描述】:
有人可以提供一个使用Test::MockObject模块中的set_bound()方法的例子吗?
set_bound() 方法能否返回 Test::MockObject 的实例(或任何其他对象)
【问题讨论】:
标签: perl unit-testing testing tdd
有人可以提供一个使用Test::MockObject模块中的set_bound()方法的例子吗?
set_bound() 方法能否返回 Test::MockObject 的实例(或任何其他对象)
【问题讨论】:
标签: perl unit-testing testing tdd
*“set_bound 方法能否返回 Test::MockObject 的实例(或任何其他对象)”*
是的。来自source:
sub set_bound {
# ...
return unless exists $bindings{reftype( $ref )};
$self->mock( $name, $bindings{reftype( $ref )} );
} # So this returns either undef, or result of mock() call
sub mock {
#...
$self;
} # So this CAN return an instance of Test::MockObject
*有人可以提供一个使用 Test::MockObject 模块中的 set_bound 方法的示例吗?*
my $value = 'X';
$mock->set_bound( 'next_value', \$value );
is( $mock->next_value, 'X' );
$var = 'Y';
is( $mock->next_value, 'Y' ); # Method result changed to new value of the variable
为什么要使用它? POD 声明“这通常比替换模拟方法更方便”。我猜“handier”在啤酒持有者的眼中,但它确实是一个不错的捷径。
【讨论】: