2015-06-23 4 views
2

У меня есть проект модульного тестирования с использованием NUnit 2.6.3 с использованием .Net 4.5. Но в конфигурации шага TeamCity сборки у меня только во время выполнения 4.0 доступны (даже если другие компоненты моего раствора компилировать против 4,5), и когда я бег моего модульного тестирования я получаю следующее исключение:Исключение BadImageFormatException при запуске тестов NUnit на TeamCity

[Step 8/9] System.ArgumentException: Specified NUnit error running tests in '[SANITIZED].UnitTest.dll' assembly 
Loading assembly is compiled for v4.0.30319, MSIL 
NUnit runner runtime is v4.0.30319, x64 
System.ArgumentException: A BadImageFormatException has been thrown while parsing the signature. This is likely due to lack of a generic context. Ensure genericTypeArguments and genericMethodArguments are provided and contain enough context. ---> System.BadImageFormatException: Could not load file or assembly '[SANITIZED]' or one of its dependencies. An attempt was made to load a program with an incorrect format. 
    at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type) 
    at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) 
    at System.ModuleHandle.ResolveTypeHandle(Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) 
    at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) 
    --- End of inner exception stack trace --- 

Server stack trace: 
    at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) 
    at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg) 
    at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) 
    at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit) 
    at NUnit.Core.CoreExtensions.InstallAdhocExtensions(Assembly assembly) 
    at NUnit.Core.Builders.TestAssemblyBuilder.Load(String path) 
    at NUnit.Core.Builders.TestAssemblyBuilder.Build(String assemblyName, Boolean autoSuites) 
    at NUnit.Core.Builders.TestAssemblyBuilder.Build(String assemblyName, String testName, Boolean autoSuites) 
    at NUnit.Core.TestSuiteBuilder.Build(TestPackage package) 
    at NUnit.Core.SimpleTestRunner.Load(TestPackage package) 
    at NUnit.Core.ProxyTestRunner.Load(TestPackage package) 
    at NUnit.Core.ProxyTestRunner.Load(TestPackage package) 
    at NUnit.Core.RemoteTestRunner.Load(TestPackage package) 
    at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs) 
    at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg) 

Exception rethrown at [0]: 
    at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) 
    at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) 
    at NUnit.Core.TestRunner.Load(TestPackage package) 
    at JetBrains.TeamCity.NUnitLauncher.NUnitRunner.LoadTest(String testAssembly, String testName, TestRunner runner) in c:\BuildAgent\work\42f5b4bce579465c\src\NUnitLauncher\src\NUnit-2.6\NUnitRunner.cs:line 53 
    at JetBrains.TeamCity.NUnitLauncher.AssemblyTest.LoadTestDomain() in c:\BuildAgent\work\42f5b4bce579465c\src\NUnitLauncher\src\AssemblyTest.cs:line 76 
    at JetBrains.TeamCity.NUnitLauncher.LoadTestDomainAction.Action(AssemblyTest test) in c:\BuildAgent\work\42f5b4bce579465c\src\NUnitLauncher\src\LoadTestDomainAction.cs:line 17 
    at JetBrains.TeamCity.NUnitLauncher.TryOneAssemblyTest.Action() in c:\BuildAgent\work\42f5b4bce579465c\src\NUnitLauncher\src\TryOneAssemblyTest.cs:line 18 
    at JetBrains.TeamCity.NUnitLauncher.TryOneAssembly.Do() in c:\BuildAgent\work\42f5b4bce579465c\src\NUnitLauncher\src\TryOneAssembly.cs:line 36 
Check correct .NET Framework version and process platform (x64, x86, MSIL) are used both in the test runner settings and involved assemblies on this machine. description. description should be non-null string of (0, 4000] size 
    at JetBrains.BuildServer.CommonLoggers.Impl.BuildProblemServiceMessageImpl.AddBuildProblem(String identity, String type, String description) in c:\BuildAgent\work\42f5b4bce579465c\src\CommonLoggers\src\Impl\BuildProblemServiceMessageImpl.cs:line 43 
    at JetBrains.TeamCity.NUnitLauncher.TryOneAssembly.Do() in c:\BuildAgent\work\42f5b4bce579465c\src\NUnitLauncher\src\TryOneAssembly.cs:line 64 
    at JetBrains.TeamCity.NUnitLauncher.NUnitRunnerBase.DoTry(TryOneAssembly aTry) in c:\BuildAgent\work\42f5b4bce579465c\src\NUnitLauncher\src\NUnitRunnerBase.cs:line 53 
    at JetBrains.TeamCity.NUnitLauncher.NUnitRunnerBase.RunOneAssembly(AssemblyTest test, ITestOrderingStrategy strategy, Boolean isRecentTestMode) in c:\BuildAgent\work\42f5b4bce579465c\src\NUnitLauncher\src\NUnitRunnerBase.cs:line 161 
    at JetBrains.TeamCity.NUnitLauncher.NUnitRunnerBase.RunInternal() in c:\BuildAgent\work\42f5b4bce579465c\src\NUnitLauncher\src\NUnitRunnerBase.cs:line 141 
    at JetBrains.TeamCity.NUnitLauncher.NUnitRunnerBase.Run() in c:\BuildAgent\work\42f5b4bce579465c\src\NUnitLauncher\src\NUnitRunnerBase.cs:line 60 

Любую идею, чтобы помочь мне настроить эти модульные тесты?

+1

Попробуйте изменить конфигурацию своей работы TeamCity, выберите ** NUnit runner ** 2.6.3 и **. NET runtime ** x86, v4.0, в настоящее время кажется, что у вас есть x64. –

+0

@MichalHosala: Спасибо, это исправило проблему! Можете ли вы опубликовать его в качестве ответа, чтобы я мог отметить его как решение и отметить вопрос как исправленный? :) –

ответ

2

На основе stacktrace и NUnit release notes мое впечатление, что проблема заключается в том, что проблема не с платформой NUnit 2.6.3 для платформы v4.0.

Это скорее, как представляется, проблема с разрядностью тест бегун NUnit, который в своей работе является 64:

NUnit бегун выполнения является v4.0.30319, x64

BadImageFormatException может быть затем выброшена, если ваша сборка MSIL скомпилированных тестов пытается загрузить некоторую библиотеку x86 или аналогично.

Простое изменение конфигурации задания TeamCity для использования 32-разрядного бегуна NUnit (.NET runtime v4.0, x86) должно устранить проблему.

Смежные вопросы