【发布时间】:2010-09-07 16:16:42
【问题描述】:
标题说明了 - MS Visual Studio 单元测试中的 TestMethods 之间会发生什么?
我在一个具有 TestInitialize 方法的 TestClass 中有一堆 TestMethods。
TestInitialize 方法在内部通过反射加载类型(例如 Type.GetType("MyContainer, MyContainerAssembly") )。 MyContainer 是一个继承自 WindsorContainer(来自 Castle Windsor)的类。
当我选择在解决方案中运行所有单元测试时,第一次调用 TestInitialize(对于第一个 TestMethod),这一切都很好。当第二个 TestMethod 执行并调用 TestInitialize 时,我的 Type.GetType 调用返回 null。
我在 TestInitialize 方法中放置了一个断点并验证了这一点。为了调试问题,我尝试在即时窗口中:
Assembly.Load("MyContainerAssembly")
哪个有效...然后:
Assembly.Load("MyContainerAssembly").GetTypes()
你知道什么?它抛出了一个 TypeLoaderException,说它找不到程序集 Castle.Windsor。检查了单元测试项目的 bin\debug 目录。它就在那里。
然后我尝试了: Assembly.Load("Castle.Windsor")
哪个有效...然后:
Assembly.Load("Castle.Windsor").GetAssemblies()
...无法加载 Castle.Core...然后
Assembly.Load("Castle.Core")
然后
Type.GetType("MyContainer, MyContainerAssembly")
再次...它返回了 Type 实例,而不是 null。
想法?
【问题讨论】:
标签: .net unit-testing visual-studio-2010 castle-windsor mstest