运行Abp.AutoMapper.Tests测试项目会给出随机结果,并且通常会因错误而失败。我特别在谈论此测试:“ AutoMapper_Inheritance_Tests.AutoMapKey_MapTo_DerivedCollection_Tests”
我在Azure DevOps中运行生成过程。我之前使用过C#Make步骤,但是将其更改为其他内容并没有帮助。即使您运行提供的构建脚本(build.ps1),结果也不会相同。这项测试可能会失败,也可能不会失败...取决于我的心情。在我看来,偶尔的失败可能与某些底层逻辑的异步性质有关。
[Fact]
public void AutoMapKey_MapTo_DerivedCollection_Tests()
{
var list1 = new List<MyAutoMapKeyClass1>
{
new MyAutoMapKeyClass1 { Id = 1, TestProp = "New test value 1"},
new MyAutoMapKeyClass1 { Id = 2, TestProp = "New test value 2"}
};
var list2 = new List<MyAutoMapKeyClass2>
{
new MyAutoMapKeyClass2 { Id = 1, TestProp = "Test value 1", Value = 5},
new MyAutoMapKeyClass2 { Id = 2, TestProp = "Test value 2", Value = 10}
};
var list3 = new List<MyAutoMapKeyClass3>
{
new MyAutoMapKeyClass3 { Id = 1, TestProp = "New test value 1"},
new MyAutoMapKeyClass3 { Id = 2, TestProp = "New test value 2"}
};
var list4 = new List<MyAutoMapKeyClass4>
{
new MyAutoMapKeyClass4 { Id = 1, TestProp = "Test value 1", Value = 5},
new MyAutoMapKeyClass4 { Id = 2, TestProp = "Test value 2", Value = 10}
};
var list5 = new List<MyAutoMapKeyClass5>
{
new MyAutoMapKeyClass5 { Id = 1, SecondId = 2, TestProp = "New test value 1"},
new MyAutoMapKeyClass5 { Id = 2, SecondId = 3, TestProp = "New test value 2"}
};
var list6 = new List<MyAutoMapKeyClass6>
{
new MyAutoMapKeyClass6 { Id = 1, SecondId = 2, TestProp = "Test value 1", Value = 5},
new MyAutoMapKeyClass6 { Id = 2, SecondId = 3, TestProp = "Test value 2", Value = 10}
};
var list7 = new List<MyAutoMapKeyClass7>
{
new MyAutoMapKeyClass7 { Id = 1, SecondId = 2, TestProp = "New test value 1"},
new MyAutoMapKeyClass7 { Id = 2, SecondId = 3, TestProp = "New test value 2"}
};
var list8 = new List<MyAutoMapKeyClass8>
{
new MyAutoMapKeyClass8 { Id = 1, SecondId = 2, TestProp = "Test value 1", Value = 5},
new MyAutoMapKeyClass8 { Id = 2, SecondId = 3, TestProp = "Test value 2", Value = 10}
};
_mapper.Map(list1, list2);
list2.Count.ShouldBe(2);
list2[0].TestProp.ShouldBe("New test value 1");
list2[0].Value.ShouldBe(5);
list2[1].TestProp.ShouldBe("New test value 2");
list2[1].Value.ShouldBe(10);
_mapper.Map(list3, list4);
list4.Count.ShouldBe(2);
list4[0].TestProp.ShouldBe("New test value 1");
list4[0].Value.ShouldBe(5);
list4[1].TestProp.ShouldBe("New test value 2");
list4[1].Value.ShouldBe(10);
_mapper.Map(list5, list6);
list6.Count.ShouldBe(2);
list6[0].TestProp.ShouldBe("New test value 1");
list6[0].Value.ShouldBe(5);
list6[1].TestProp.ShouldBe("New test value 2");
list6[1].Value.ShouldBe(10);
_mapper.Map(list7, list8);
list8.Count.ShouldBe(2);
list8[0].TestProp.ShouldBe("New test value 1");
list8[0].Value.ShouldBe(5);
list8[1].TestProp.ShouldBe("New test value 2");
list8[1].Value.ShouldBe(10);
}
}
失败的块实际上是'_mapper.Map(list1,list2);' 预期结果将始终相同,即5。相反,我看到了错误:
针对C:\ agents \ agent3_work \ 1 \ s \ test \ Abp.AutoMapper.Tests \ bin \ Debug \ netcoreapp2.2 \ Abp.AutoMapper.Tests.dll(.NETCoreApp,Version = v2.2)运行测试 Microsoft(R)测试执行命令行工具版本15.9.0 版权所有(c)Microsoft Corporation。保留所有权利。
开始执行测试,请稍候... [xUnit.net 00:00:02.79] Abp.AutoMapper.Tests.AutoMapper_Inheritance_Tests.AutoMapKey_MapTo_DerivedCollection_Tests [FAIL] Abp.AutoMapper.Tests.AutoMapper_Inheritance_Tests.AutoMapKey_MapTo_DerivedCollection_Tests失败 错误信息: Shouldly.ShouldAssertException:list2 [0] .Value 应该 5 但是是 0 堆栈跟踪: 在Abp.AutoMapper.Tests.AutoMapper_Inheritance_Tests.AutoMapKey_MapTo_DerivedCollection_Tests()中位于C:\ agents \ agent3_work \ 1 \ s \ test \ Abp.AutoMapper.Tests \ AutoMapper_Inheritance_Tests.cs:line 219
同样,即使我在本地计算机上运行测试,结果也可能相同,即该测试在此特定位置失败。但是,如果我立即在“测试资源管理器”中单独重新运行此测试,那么它将毫无问题。