C# Azure DevOps测试在发布时成功运行,在调试时无限期运行
我在解决方案中使用Autofac和Automapper。我编写了一个单元测试,它在本地运行时没有任何问题。当我创建pull请求时,单元测试在RELEASE中成功运行;然而,在调试中,它无限期地运行,一段时间后(即45分钟),它就失败了 我尝试以这样的方式调整代码,使其只使用Autofac的C# Azure DevOps测试在发布时成功运行,在调试时无限期运行,c#,azure-devops,automapper,autofac,mstest,C#,Azure Devops,Automapper,Autofac,Mstest,我在解决方案中使用Autofac和Automapper。我编写了一个单元测试,它在本地运行时没有任何问题。当我创建pull请求时,单元测试在RELEASE中成功运行;然而,在调试中,它无限期地运行,一段时间后(即45分钟),它就失败了 我尝试以这样的方式调整代码,使其只使用Autofac的容器,而不是范围,以解决某些依赖关系。我正在尝试测试我的应用程序的分辨率以及映射器配置文件的assertconfigurationsvalid;但问题依然存在 public static ICo
容器
,而不是范围
,以解决某些依赖关系。我正在尝试测试我的应用程序的分辨率以及映射器配置文件的assertconfigurationsvalid
;但问题依然存在
public static IContainer Configure()
{
var builder = new ContainerBuilder();
//Application
builder.RegisterType<DerivedBatchVolumesApplication>().AsSelf();
//Features
builder.RegisterType<QEndOfMonthCalculator>().As<IQEndOfMonthCalculator>();
builder.RegisterType<QProgressiveRounder>().As<IQProgressiveRounder>();
//Configuration
builder.Register(x => QEndOfMonthCalculatorConfiguration.FromMetadata()).As<IQEndOfMonthCalculatorConfiguration>();
builder.Register(x => QDerivedBatchVolumesConfiguration.FromMetadata()).As<IQDerivedBatchVolumesConfiguration>();
//Data
builder.RegisterType<QTranTicketRepository>().As<IQRepository<TranTicketDO>>();
builder.RegisterType<QCtBatchRepository>().As<IQRepository<CtBatchDO>>();
builder.RegisterType<QPaystationRepository>().As<IQRepository<PaystationDO>>();
builder.RegisterType<QTicketVolRepository>().As<IQRepository<TicketVolDO>>();
builder.RegisterType<QSctrlRelatedCtrRepository>().As<IQRepository<SctrlRelatedCtrDO>>();
builder.RegisterType<QAllocVolRepository>().As<IQRepository<AllocVolDO>>();
//Mapper
builder.RegisterType<QMapper>().As<IQMapper>();
builder.RegisterAssemblyTypes(AppDomain.CurrentDomain.GetAssemblies())
.Where(x => x.GetCustomAttribute<InjectableAttribute>() != null)
.AsImplementedInterfaces();
//Data Access
builder.RegisterType<TranTicket>().AsSelf();
builder.RegisterType<CtBatch>().AsSelf();
builder.RegisterType<Paystation>().AsSelf();
builder.RegisterType<TicketVol>().AsSelf();
builder.RegisterType<SctrlRelatedCtr>().AsSelf();
builder.RegisterType<AllocVol>().AsSelf();
return builder.Build();
}
[TestInitialize]
public void Setup()
{
var container = ContainerConfiguration.Configure();
_scope = container.BeginLifetimeScope();
_mapper = _scope.Resolve<IQMapper>();
}
[TestCleanup]
public void Cleanup()
{
_scope.Dispose();
}
[TestMethod]
public void MapperConfigurations_AreValid()
{
_mapper.AssertConfigurationIsValid();
}
[TestInitialize]
public void Setup()
{
_endOfMonthCalculator = new Mock<IQEndOfMonthCalculator>();
_tranTicket = new Mock<IQRepository<TranTicketDO>>();
_ctBatch = new Mock<IQRepository<CtBatchDO>>();
_paystation = new Mock<IQRepository<PaystationDO>>();
_ticketVol = new Mock<IQRepository<TicketVolDO>>();
_sctrlRelatedCtr = new Mock<IQRepository<SctrlRelatedCtrDO>>();
_allocVol = new Mock<IQRepository<AllocVolDO>>();
_derBatchVolConfiguration = new Mock<IQDerivedBatchVolumesConfiguration>();
_container = ContainerConfiguration.Configure();
_progressiveRounder = _container.Resolve<IQProgressiveRounder>();
_mapper = _container.Resolve<IQMapper>();
}
[TestCleanup]
public void Cleanup()
{
_container.Dispose();
}
[TestMethod]
public void DerivedBatchVolumesApplication_Resolves()
{
//Arrange & Act
var application = _container.Resolve<DerivedBatchVolumesApplication>();
//Assert
application.ShouldNotBeNull();
application.ShouldBeOfType<DerivedBatchVolumesApplication>();
}
publicstaticontainer配置()
{
var builder=new ContainerBuilder();
//应用
builder.RegisterType().AsSelf();
//特征
builder.RegisterType().As();
builder.RegisterType().As();
//配置
Register(x=>QEndOfMonthCalculatorConfiguration.FromMetadata()).As();
Register(x=>QDerivedBatchVolumesConfiguration.FromMetadata()).As();
//资料
builder.RegisterType().As();
builder.RegisterType().As();
builder.RegisterType().As();
builder.RegisterType().As();
builder.RegisterType().As();
builder.RegisterType().As();
//制图员
builder.RegisterType().As();
builder.RegisterAssemblyTypes(AppDomain.CurrentDomain.GetAssemblyTypes())
.Where(x=>x.GetCustomAttribute()!=null)
.a实现接口();
//数据存取
builder.RegisterType().AsSelf();
builder.RegisterType().AsSelf();
builder.RegisterType().AsSelf();
builder.RegisterType().AsSelf();
builder.RegisterType().AsSelf();
builder.RegisterType().AsSelf();
返回builder.Build();
}
[测试初始化]
公共作废设置()
{
var container=ContainerConfiguration.Configure();
_scope=container.BeginLifetimeScope();
_映射器=_scope.Resolve();
}
[测试清理]
公共空间清理()
{
_scope.Dispose();
}
[测试方法]
public void MapPerConfiguration\u AreValid()
{
_assertConfigurationsValid();
}
[测试初始化]
公共作废设置()
{
_endOfMonthCalculator=新建模拟();
_tranTicket=newmock();
_ctBatch=newmock();
_paystation=new Mock();
_ticketVol=newmock();
_sctrlRelatedCtr=新模拟();
_allocVol=新模拟();
_derBatchVolConfiguration=new Mock();
_container=ContainerConfiguration.Configure();
_progressiveRounder=_container.Resolve();
_映射器=_container.Resolve();
}
[测试清理]
公共空间清理()
{
_container.Dispose();
}
[测试方法]
public void derivedbackvolumesapplication_Resolves()
{
//安排和行动
var应用程序=_container.Resolve();
//断言
application.ShouldNotBeNull();
application.ShouldBeOfType();
}
我的期望是,单元测试将成功地为调试运行,就像在发行版中一样。它在本地工作吗?您是否对测试被卡住的位置有任何堆栈跟踪?是的,它在本地甚至在构建服务器上都可以工作,但仅适用于发布版本。它不会生成任何堆栈跟踪,但当它开始命中使用依赖项生成器模块的单元测试时,它只是卡在那里。您可以添加一些跟踪来尝试定位它卡在哪里吗?它在本地工作吗?您是否对测试被卡住的位置有任何堆栈跟踪?是的,它在本地甚至在构建服务器上都可以工作,但仅适用于发布版本。它不会生成任何堆栈跟踪,但是当它开始命中使用依赖项生成器模块的单元测试时,它只是卡在那里。您可以添加一些跟踪来尝试定位它卡在哪里吗?