0

我正在尝试使用 NUnit 和标准控制台(GUI 或非 GUI)运行器测试 Windows Phone 7.1 类库。

在我的问题之后,我在下面找到了这个: http ://dotneteers.net/blogs/vbandi/archive/2012/08/08/using-nunit-to-test-windows-phone-7-applications-part- 1.aspx

所以我几乎可以肯定这是我自己的一个愚蠢的问题。

每次我尝试加载我的程序集测试时,我都会收到此错误:

System.TypeLoadException:无法从程序集'mscorlib,版本 = 2.0.0.0,文化 = 中性,PublicKeyToken = b77a5c561934e089' 加载类型'System.Runtime.Versioning.TargetFrameworkAttribute'。

如需更多信息,请使用异常详细信息菜单项。

* 这里是“详细信息” *

System.TypeLoadException...

服务器堆栈跟踪: en System.ModuleHandle.ResolveType(Int32 typeToken, RuntimeTypeHandle* typeInstArgs, Int32 typeInstCount, RuntimeTypeHandle* methodInstArgs, Int32 methodInstCount) en System.ModuleHandle.ResolveTypeHandle(Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) .Reflection.Module.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) en System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, Module decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] 属性,IList derivedAttributes,RuntimeType& attributeType,RuntimeMethodHandle& ctor, Boolean& ctorHasParameters, Boolean& isVarArg) en System.Reflection.CustomAttribute.GetCustomAttributes(Module decoratedModule, Int32 DecorationMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes) en System.Reflection.CustomAttribute.GetCustomAttributes(Assembly assembly, RuntimeType caType ) en System.Reflection.Assembly.GetCustomAttributes(Type attributeType, Boolean inherit) en NUnit.Core.ActionsHelper.GetActionsFromAttributeProvider(ICustomAttributeProvider attributeProvider) en NUnit.Core.TestAssembly..ctor(Assembly assembly, String path) en NUnit.Core.Builders .TestAssemblyBuilder.BuildTestAssembly(Assembly assembly, String assemblyName, IList fixtures, Boolean autoSuites)ctorHasParameters, Boolean& isVarArg) en System.Reflection.CustomAttribute.GetCustomAttributes(Module decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes) en System.Reflection.CustomAttribute.GetCustomAttributes(Assembly assembly, RuntimeType caType) en System. Reflection.Assembly.GetCustomAttributes(Type attributeType, Boolean inherit) en NUnit.Core.ActionsHelper.GetActionsFromAttributeProvider(ICustomAttributeProvider attributeProvider) en NUnit.Core.TestAssembly..ctor(Assembly assembly, String path) en NUnit.Core.Builders.TestAssemblyBuilder.BuildTestAssembly (程序集程序集、字符串程序集名称、IList 固定装置、布尔自动套件)ctorHasParameters, Boolean& isVarArg) en System.Reflection.CustomAttribute.GetCustomAttributes(Module decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes) en System.Reflection.CustomAttribute.GetCustomAttributes(Assembly assembly, RuntimeType caType) en System. Reflection.Assembly.GetCustomAttributes(Type attributeType, Boolean inherit) en NUnit.Core.ActionsHelper.GetActionsFromAttributeProvider(ICustomAttributeProvider attributeProvider) en NUnit.Core.TestAssembly..ctor(Assembly assembly, String path) en NUnit.Core.Builders.TestAssemblyBuilder.BuildTestAssembly (程序集程序集、字符串程序集名称、IList 固定装置、布尔自动套件)CustomAttribute.GetCustomAttributes(Module decoratedModule,Int32 decoratedMetadataToken,Int32 pcaCount,RuntimeType attributeFilterType,Boolean mustBeInheritable,IList derivedAttributes) en System.Reflection.CustomAttribute.GetCustomAttributes(Assembly 程序集,RuntimeType caType) en System.Reflection.Assembly.GetCustomAttributes(Type attributeType,Boolean inherit) en NUnit.Core.ActionsHelper.GetActionsFromAttributeProvider(ICustomAttributeProvider attributeProvider) en NUnit.Core.TestAssembly..ctor(Assembly assembly, String path) en NUnit.Core.Builders.TestAssemblyBuilder.BuildTestAssembly(Assembly assembly, String assemblyName, IList fixtures,布尔自动套件)CustomAttribute.GetCustomAttributes(Module decoratedModule,Int32 decoratedMetadataToken,Int32 pcaCount,RuntimeType attributeFilterType,Boolean mustBeInheritable,IList derivedAttributes) en System.Reflection.CustomAttribute.GetCustomAttributes(Assembly 程序集,RuntimeType caType) en System.Reflection.Assembly.GetCustomAttributes(Type attributeType,Boolean inherit) en NUnit.Core.ActionsHelper.GetActionsFromAttributeProvider(ICustomAttributeProvider attributeProvider) en NUnit.Core.TestAssembly..ctor(Assembly assembly, String path) en NUnit.Core.Builders.TestAssemblyBuilder.BuildTestAssembly(Assembly assembly, String assemblyName, IList fixtures,布尔自动套件)Boolean mustBeInheritable, IList derivedAttributes) en System.Reflection.CustomAttribute.GetCustomAttributes(Assembly assembly, RuntimeType caType) en System.Reflection.Assembly.GetCustomAttributes(Type attributeType, Boolean inherit) en NUnit.Core.ActionsHelper.GetActionsFromAttributeProvider(ICustomAttributeProvider attributeProvider) en NUnit .Core.TestAssembly..ctor(Assembly assembly, String path) en NUnit.Core.Builders.TestAssemblyBuilder.BuildTestAssembly(Assembly assembly, String assemblyName, IList fixtures, Boolean autoSuites)Boolean mustBeInheritable, IList derivedAttributes) en System.Reflection.CustomAttribute.GetCustomAttributes(Assembly assembly, RuntimeType caType) en System.Reflection.Assembly.GetCustomAttributes(Type attributeType, Boolean inherit) en NUnit.Core.ActionsHelper.GetActionsFromAttributeProvider(ICustomAttributeProvider attributeProvider) en NUnit .Core.TestAssembly..ctor(Assembly assembly, String path) en NUnit.Core.Builders.TestAssemblyBuilder.BuildTestAssembly(Assembly assembly, String assemblyName, IList fixtures, Boolean autoSuites)ActionsHelper.GetActionsFromAttributeProvider(ICustomAttributeProvider attributeProvider) en NUnit.Core.TestAssembly..ctor(Assembly assembly, String path) en NUnit.Core.Builders.TestAssemblyBuilder.BuildTestAssembly(Assembly assembly, String assemblyName, IList fixtures, Boolean autoSuites)ActionsHelper.GetActionsFromAttributeProvider(ICustomAttributeProvider attributeProvider) en NUnit.Core.TestAssembly..ctor(Assembly assembly, String path) en NUnit.Core.Builders.TestAssemblyBuilder.BuildTestAssembly(Assembly assembly, String assemblyName, IList fixtures, Boolean autoSuites)
en NUnit.Core.Builders.TestAssemblyBuilder.Build(String assemblyName, Boolean autoSuites) en NUnit.Core.Builders.TestAssemblyBuilder.Build(String assemblyName, String testName, Boolean autoSuites) en NUnit.Core.TestSuiteBuilder.BuildSingleAssembly(TestPackage package)
en NUnit.Core.TestSuiteBuilder.Build(TestPackage package) en NUnit.Core.SimpleTestRunner.Load(TestPackage package) en NUnit.Core.ProxyTestRunner.Load(TestPackage package) en NUnit.Core.ProxyTestRunner.Load(TestPackage package) en NUnit .Core.RemoteTestRunner.Load(TestPackage package) en System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs) en System.Runtime .Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs) en System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr , 布尔 fExecuteInContext)

在 [0] 处重新抛出异常: en System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) en System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) en NUnit.Core。 TestRunner.Load(TestPackage package) en NUnit.Util.TestDomain.Load(TestPackage package) en NUnit.Util.TestLoader.LoadTest(String testName)

有人知道我找不到什么问题吗?

4

1 回答 1

0

我发现(以一种非常容易解释的方式)问题是什么,解决方案是什么(或者更好地说是替代方案)。

问题是 NUnit 控制台运行程序(或 GUI 运行程序)在不同的环境下执行。我的意思是 aConsole Application或 aWinforms application然后他们尝试加载一个Windows Phone库,这就是问题所在。

解决方案是使用 Re-Sharper、NCrunch、Visual NUnit 或类似的东西执行测试,而不是使用 NUnit 默认运行程序。

我正在使用 Visual NUnit。 http://visualstudiogallery.msdn.microsoft.com/c8164c71-0836-4471-80ce-633383031099

:-)

问候并感谢所有阅读我的问题的人。

于 2012-10-21T19:38:44.503 回答