对于我的内装剂 结束测试, 重要的是,我的测试组装 不要预先装上 影子的影印 附属组装。
Assembly T is the Testframework that loads and tests Assembly A. Assembly A depends on interfaces defined in B.
为测试目的,我必须替换A类中一些静态成员,但不能在施工期间使用。
以下是一些假代码, 说明我所处的困境:
A_assembly = Assembly.LoadFrom("A.dll");
A_type = A_assembly.GetType("TheSingleton.Master", true);
MethodInfo Master_Init_Info = type.GetMethod("Init", BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
//before init is called some things need to be replaced
FieldInfo semiknown = A_type.GetField("needsmocking", BindingFlags.Public | BindingFlags.Static));
??? mock_semiknown = MockRepository.GenerateMock<???>();
semiknown.SetValue((???)mock_semiknown, mock_semiknown);
//testing makes only sense if that static is replaced.
Master_Init_Info.Invoke(null, null);
- I can access the type via
semiknown.FieldType
but what good does that do me? Can i use that information somehow to create the mock and replace the static member with it? - Suppose i get the type and am able to replace the static member - how can i build my expectancies in the mock?