簡體   English   中英

Visual Studio 2015單元測試不一致

[英]Visual Studio 2015 Unit Test Inconsistency

在VS2013上升級到VS2015后,我收到不一致的單元測試結果。 在VS2013上,單元測試始終通過。 在VS2015中,如果全部一次運行或者是Jenkins自動構建,則單元測試將失敗。 如果單元測試單獨運行或所有失敗的測試一次運行,則它們通過。

這可能是EF6問題。 運行所有測試時收到的錯誤消息是...

Test Name:  GetQuoteService_NoExceptions
Test FullName:  MEA.SmartApp.Business.Factories.APV.UnitTests.QuoteFactoryTest.GetQuoteService_NoExceptions
Test Source:    C:\MetLife_Sourcecode\Common\DEV2\MEA.Smartapp.Common\Unit Tests\MEA.SmartApp.Business.Factories.APV.UnitTests\QuoteFactoryTest.cs : line 15
Test Outcome:   Failed
Test Duration:  0:00:00.00737

結果StackTrace:

at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName)
   at System.Data.Entity.Internal.AppConfig.<.ctor>b__2(ProviderElement e)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at System.Data.Entity.Internal.AppConfig.<.ctor>b__1()
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at System.Lazy`1.get_Value()
   at System.Data.Entity.Internal.AppConfig.get_DbProviderServices()
   at System.Data.Entity.Infrastructure.DependencyResolution.AppConfigDependencyResolver.RegisterDbProviderServices()
   at System.Data.Entity.Infrastructure.DependencyResolution.AppConfigDependencyResolver.GetServiceFactory(Type type, String name)
   at System.Data.Entity.Infrastructure.DependencyResolution.AppConfigDependencyResolver.<>c__DisplayClass1.<GetService>b__0(Tuple`2 t)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at System.Data.Entity.Infrastructure.DependencyResolution.AppConfigDependencyResolver.GetService(Type type, Object key)
   at System.Data.Entity.Infrastructure.DependencyResolution.DbDependencyResolverExtensions.GetServiceAsServices(IDbDependencyResolver resolver, Type type, Object key)
   at System.Data.Entity.Infrastructure.DependencyResolution.AppConfigDependencyResolver.GetServices(Type type, Object key)
   at System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.<>c__DisplayClass6.<GetServices>b__5(IDbDependencyResolver r)
   at System.Linq.Enumerable.<SelectManyIterator>d__1`2.MoveNext()
   at System.Linq.Enumerable.<ConcatIterator>d__1`1.MoveNext()
   at System.Linq.Enumerable.<OfTypeIterator>d__1`1.MoveNext()
   at System.Data.Entity.Utilities.IEnumerableExtensions.Each[T](IEnumerable`1 ts, Action`1 action)
   at System.Data.Entity.Infrastructure.DependencyResolution.InternalConfiguration.Lock()
   at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.<.ctor>b__1()
   at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Lazy`1.get_Value()
   at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.GetConfiguration()
   at System.Data.Entity.DbContext.InitializeLazyInternalContext(IInternalConnection internalConnection, DbCompiledModel model)
   at System.Data.Entity.DbContext..ctor(String nameOrConnectionString)
   at MEA.SmartApp.Contexts.APV.AVMDB..ctor() in C:\MetLife_Sourcecode\Common\DEV2\MEA.Smartapp.Common\DataAccessLayer\MEA.SmartApp.Contexts.APV\AVMDB.Context.cs:line 19
   at MEA.SmartApp.Business.Factories.APV.QuoteFactory.GetAvmBusinessService() in C:\MetLife_Sourcecode\Common\DEV2\MEA.Smartapp.Common\BusinessLogicLayer\MEA.SmartApp.Business.Factories.APV\QuoteFactory.cs:line 65
   at MEA.SmartApp.Business.Factories.APV.QuoteFactory.GetQuoteService(APVTransactionCode transactionCode) in C:\MetLife_Sourcecode\Common\DEV2\MEA.Smartapp.Common\BusinessLogicLayer\MEA.SmartApp.Business.Factories.APV\QuoteFactory.cs:line 46
   at MEA.SmartApp.Business.Factories.APV.UnitTests.QuoteFactoryTest.GetQuoteService_NoExceptions() in C:\MetLife_Sourcecode\Common\DEV2\MEA.Smartapp.Common\Unit Tests\MEA.SmartApp.Business.Factories.APV.UnitTests\QuoteFactoryTest.cs:line 18
Result Message: 
Test method MEA.SmartApp.Business.Factories.APV.UnitTests.QuoteFactoryTest.GetQuoteService_NoExceptions threw exception: 
**System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded**. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

*我意識到這並不是真正的單元測試,因為它正嘗試連接到數據庫,因此,如果您對如何解決該問題有任何建議,請告訴我。

@KeithPayne-在使用其他不同的其他單元測試集運行失敗的單元測試之后,我能夠證明是另一個測試導致實體框架測試失敗。 因此,您對並行執行是正確的。

該單元測試的兩個突出屬性導致實體框架單元測試失敗。

  1. 單元測試涵蓋了VB.NET代碼,而我的測試套件中的所有其他人都測試了C#代碼。
  2. 單元測試最初是在VS2008中創建的,其測試屬性為DeploymentItem(“ MIGTRX.dll”)。 MIGTRX是正在測試的VB.NET項目。 此屬性的原因是使用受測類的訪問器類公開公開私有方法,以便可以對其進行單元測試。 (注意:我意識到這是一個不好的做法,但這是我繼承的舊版代碼測試)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM