Visual Studio 2015单元测试不一致性
本文关键字:不一致性 单元测试 2015 Studio Visual | 更新日期: 2023-09-27 18:05:31
在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
Result 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 -在使用不同的其他单元测试集运行失败的单元测试后,我能够证明是另一个测试导致实体框架测试失败。所以你说的并行执行是对的。
该单元测试有两个突出的属性导致实体框架单元测试失败。
- 单元测试覆盖VB。. NET代码,而我的测试套件中所有其他测试的都是c#代码。
- 单元测试最初是在VS2008中创建的,并且具有DeploymentItem("MIGTRX.dll")的测试属性。MIGTRX是VB。正在测试的。NET项目。使用此属性的原因是使用test的访问器类下的类公开公开私有方法,以便对其进行单元测试。(注意:我意识到这是一个不好的做法,但它是遗留代码测试,我继承)