- 作者:zhaozj
- 发表时间:2020-12-23 10:38
- 来源:未知
Using NMock and DynamicMocks in Test Driven Development I was pairing with someone last night trying to test the Command pattern which lead to a useful example of using NMock to create a dynamic Mock object to help test it. Here are some notes on how NMock can be used to create DynamicMock objects based on an interface to quickly create loosely-coupled test code.
The command pattern allows you to wrap a command inside an object so that you can pass it to another object to execute that object. We were using a simplified version of the pattern where we had a command interface that has an Execute method and a Results property to retrieve the results:
public interface ICommand
{
void Execute();
string Result{ get; }
}