HippoMocks用于动态mock生成 |
|
准备工作 |
// In [ClassUnderTest]Test.cpp file. |
设置期望: |
mockEngine.NeverCall(mock, CollaboratorService::methodName); |
设置期望: |
mockEngine.OnCall(mock, CollaboratorService::methodName); |
设置期望: |
mockEngine.OnCall(mock, CollaboratorService::methodName).With(arg1, arg2, ...); |
设置期望: |
mockEngine.ExpectCall(mock, CollaboratorService::methodName); |
设置期望: |
mockEngine.ExpectCall(mock, CollaboratorService::methodName).With(arg1, arg2, ...); |
设置期望: |
mockEngine.autoExpect = false; |
设置期望: |
mockEngine.ExpectCall(mock, CollaboratorService::methodName1); |
显式验证 |
mockEngine.VerifyAll(); |
3.3 用于C#的单元测试框架
对于C#,我们推荐使用NUnit(目前为2.5版)加RhinoMocks(目前为3.6版)的组合。如下的表格演示了如何使用这两个框架。
NUnit的基本用法 |
|
Test Fixture和Test Method |
using NUnit.Framework; // Temporarily ignore a test case. [Test] [Ignore] } |
Test Runner |
NUnit提供了GUI界面的Test Runner,只需把编译生成的程序集(assembly)加载到该Test Runner中即可。 |