2013-11-01 5 views
2

유닛 테스트에서 세트를 얻었습니다 (resharper를 사용하여 모두 실행하면이 오류가 발생 함)전체 실행시 유닛 테스트가 실패했습니다 - API 제한 : 어셈블리가 이미 다른 위치에서로드되었습니다

SetUp : System.TypeInitializationException : The type initializer for 'FakeItEasy.Core.FakeScope' threw an exception. ----> System.IO.FileLoadException : API restriction: The assembly 'file:///C:\Users\abrown\Documents\Repos\ink.services.jetstar\My.Namespace.Tests.Unit\bin\Debug\My.Namespace.dll' has already loaded from a different location. It cannot be loaded from a new location within the same appdomain.

개별적으로 실행하면 통과합니다. 또한 아래 예외

는,이 같은 라인에 실패하는 것 :

[SetUp] 
public void SetUp() 
{ 
    _myFake = A.Fake<ISomething>(); 

편집

나는 '표준'NUnit과 테스트 러너를 사용하는 경우도 발생합니다. @ 데이비드 - 아르노으로

이 코멘트에, 완전성에 대한

(만 다시 선명 위해 명백하게)을 해결합니다 ReSharper에서 주자의 설정을 변경하여 말했다, 여기에 전체 스택 추적

My.CompanyNamespace.ProjectName.Tests.Unit.DownloadAndStoreContentTests.gets_content_downloader_for_each_section_in_index: SetUp : System.TypeInitializationException : The type initializer for 'FakeItEasy.Core.FakeScope' threw an exception. ----> System.IO.FileLoadException : API restriction: The assembly 'file:///C:\Users\abrown\Documents\Repos\My.CompanyNamespace\My.CompanyNamespace.ProjectName.Tests.Unit\bin\Debug\My.CompanyNamespace.ProjectName.dll' has already loaded from a different location. It cannot be loaded from a new location within the same appdomain.

at FakeItEasy.Core.FakeScope.get_Current() at FakeItEasy.IoC.DictionaryContainer.<>c_DisplayClass1 1.<Register>b__0(DictionaryContainer c) at FakeItEasy.IoC.DictionaryContainer.Resolve(Type componentType) at FakeItEasy.ServiceLocator.Resolve[T]() at FakeItEasy.RootModule.<RegisterDependencies>b__3(DictionaryContainer c) at FakeItEasy.IoC.DictionaryContainer.<>c__DisplayClass1 1.b_0(DictionaryContainer c) at FakeItEasy.IoC.DictionaryContainer.Resolve(Type componentType) at FakeItEasy.ServiceLocator.ResolveT at FakeItEasy.RootModule.b_1a(DictionaryContainer c) at FakeItEasy.IoC.DictionaryContainer.<>c_DisplayClass1 1.<Register>b__0(DictionaryContainer c) at FakeItEasy.IoC.DictionaryContainer.Resolve(Type componentType) at FakeItEasy.ServiceLocator.Resolve[T]() at FakeItEasy.RootModule.<RegisterDependencies>b__19(DictionaryContainer c) at FakeItEasy.IoC.DictionaryContainer.<>c__DisplayClass1 1.b__0(DictionaryContainer c) at FakeItEasy.IoC.DictionaryContainer.Resolve(Type componentType) at FakeItEasy.ServiceLocator.ResolveT at FakeItEasy.A.FakeT at My.CompanyNamespace.ProjectName.Tests.Unit.DownloadAndStoreContentTests.SetUp() in c:\Users\abrown\Documents\Repos\My.CompanyNamespace\My.CompanyNamespace.ProjectName.Tests.Unit\DownloadAndStoreContentTests.cs:line 23 --FileLoadException at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark) at System.Reflection.Assembly.ReflectionOnlyLoadFrom(String assemblyFile) at FakeItEasy.Core.ApplicationDirectoryAssembliesTypeCatalogue.GetAllAvailableAssemblies() at FakeItEasy.Core.ApplicationDirectoryAssembliesTypeCatalogue..ctor() at FakeItEasy.ImportsModule.b_1(DictionaryContainer c) at FakeItEasy.IoC.DictionaryContainer.SingletonResolver 1.UnresolvedState.Resolve(DictionaryContainer container) at FakeItEasy.IoC.DictionaryContainer.<>c__DisplayClass1 1.b_0(DictionaryContainer c) at FakeItEasy.IoC.DictionaryContainer.Resolve(Type componentType) at FakeItEasy.ServiceLocator.ResolveT at FakeItEasy.ImportsModule.b_0(DictionaryContainer c) at FakeItEasy.IoC.DictionaryContainer.SingletonResolver 1.UnresolvedState.Resolve(DictionaryContainer container) at FakeItEasy.IoC.DictionaryContainer.<>c__DisplayClass1 1.b_0(DictionaryContainer c) at FakeItEasy.IoC.DictionaryContainer.Resolve(Type componentType) at FakeItEasy.ServiceLocator.ResolveT at FakeItEasy.ImportsModule.b_4[T](DictionaryContainer c) at FakeItEasy.IoC.DictionaryContainer.SingletonResolver 1.UnresolvedState.Resolve(DictionaryContainer container) at FakeItEasy.IoC.DictionaryContainer.<>c__DisplayClass1 1.b__0(DictionaryContainer c) at FakeItEasy.IoC.DictionaryContainer.Resolve(Type componentType) at FakeItEasy.ServiceLocator.ResolveT at FakeItEasy.Core.FakeScope.RootScope..ctor() at FakeItEasy.Core.FakeScope..cctor()

입니다
+0

모의 테스트를 시작하기 전에 원본 어셈블리를로드하는 것과 같은 테스트를하는 것 같습니다. – SLaks

+0

어디에서 그렇게 할 수 있습니까? – Alex

+0

나는 잘 모른다. 코드를 자세히 읽어보십시오. – SLaks

답변

4

나는이 발생 생각하기 때문에 (또는 거의) 시작, FakeItEasy scans its working directory looking for DLLs that may include extension points

  1. ,
  2. 요 U는 동일한 어셈블리의 사본을 포함하는 적어도 두있는 다른 디렉토리, 여러 시험 재를 가지며,
  3. 테스트 주자
  4. 동일한 AppDomain에의 테스트를 실행하는 것을

이유를 각 시험 재의 테스트를 실행하는 병렬 작업의 어셈블리는 병렬성 때문이 아니라 테스트 러너가 별도의 AppDomains에서 어셈블리를 실행하기 때문에 발생합니다.

다른 해결 방법은 별도의 AppDomains (예 : NUnit의 /domain=Multiple 매개 변수 사용) 또는 별도 프로세스 (/process=Multiple)로 어셈블리 테스트를 실행하는 것입니다. 많은 테스트 주자가 이러한 옵션을 지원할 것으로 기대합니다. 나는 ReSharper 8을 가지고 있지 않지만,

우리는 FakeItEasy를 어셈블리로드 실패에 대해 더 용감하게 만드는 작업을하고 있습니다. FakeItEasy issue 189에 세부 정보를 추가했습니다. 제출해 주셔서 감사합니다.

업데이트 위의 189 문제는 FakeItEasy 1.15.0에서 수정되었습니다. Get it or a later version from NuGet!