1 回答

TA貢獻(xiàn)1775條經(jīng)驗 獲得超11個贊
經(jīng)過大量跟蹤后,我發(fā)現(xiàn)原因不是 NUnit 或 TeamCity,而是因為我使用了Kentico的庫,特別是我使用 Kentico 的CMS.Tests庫來幫助對我的自定義 Kentico 代碼進(jìn)行單元測試,如此處所述。
因此,我更新了我的問題以更具體地針對 Kentico,并將在下面提供解決此問題的解決方案。
確定根本原因
經(jīng)過一番互聯(lián)網(wǎng)搜索后,我發(fā)現(xiàn) NUnit 控制臺運行器有一個--trace 命令行選項。通過傳入,--trace=Verbose我能夠?qū)⒏櫸募懭霝榭刂婆_運行程序設(shè)置的工作目錄,然后比較兩臺機(jī)器。我的本地開發(fā)機(jī)器顯示所有裝置都已正確找到,但 TeamCity 服務(wù)器會生成跟蹤文件,其輸出類似于:
InternalTrace: Initializing at level Debug
14:41:48.559 Debug [ 5] DefaultTestAssemblyBuilder: Loading D:\TeamCity\buildAgent\work\4a231fb0e41e27f5\Tests\rwy.common.core.tests\bin\Build\rwy.common.core.tests.dll in AppDomain domain-
14:41:48.570 Debug [ 5] DefaultTestAssemblyBuilder: Examining assembly for test fixtures
14:41:48.579 Debug [ 5] DefaultTestAssemblyBuilder: Found 12 classes to examine
14:41:48.691 Error [ 5] DefaultTestAssemblyBuilder: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
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.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.IsCustomAttributeDefined(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Int32 attributeCtorToken, Boolean mustBeInheritable)
at System.Reflection.CustomAttribute.IsDefined(RuntimeMethodInfo method, RuntimeType caType, Boolean inherit)
at NUnit.Framework.Internal.Reflect.GetMethodsWithAttribute(Type fixtureType, Type attributeType, Boolean inherit)
at NUnit.Framework.Internal.TestFixture..ctor(ITypeInfo fixtureType, Object[] arguments)
at NUnit.Framework.Internal.Builders.DefaultSuiteBuilder.BuildFrom(ITypeInfo typeInfo)
at NUnit.Framework.Api.DefaultTestAssemblyBuilder.GetFixtures(Assembly assembly, IList names)
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
我不明白的部分是參考,Microsoft.VisualStudio.QualityTools.UnitTestFramework因為這與 NUnit 無關(guān) - 那是 MSTest 庫,我的項目中根本沒有 MSTest 單元測試。
那時我意識到這是一個 Kentico 問題——因為CMS.Tests.dll被引用來幫助編寫虛假 Info 對象和提供程序的 Kentico適用于 NUnit和MSTest。
在我的開發(fā)機(jī)器Microsoft.VisualStudio.QualityTools.UnitTestFramework上安裝了 Visual Studio,正如這個問題中所解釋的那樣,這意味著每次我運行測試時都沒有問題 - 可以在我的系統(tǒng)上找到依賴的 DLL。但是,除非明確安裝,否則這在構(gòu)建服務(wù)器上永遠(yuǎn)不可用。
解決方案
為了解決這個問題,我遵循了這個建議:
復(fù)制
Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
到我的解決方案中并將其提交給我的倉庫。在我的所有測試項目中包含對這個程序集的引用,確保
Copy Local
是真的。
通過簡單地引用這個 DLL,構(gòu)建會將它與所有其他依賴項一起復(fù)制到bin
文件夾中,然后可以在它不是全局可用的環(huán)境中使用。
- 1 回答
- 0 關(guān)注
- 123 瀏覽
添加回答
舉報