Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing 使用Autofixture GuardClauseSertion在单元测试中引发System.BadImageFormatException异常_Unit Testing_Idioms_Autofixture_Badimageformatexception - Fatal编程技术网

Unit testing 使用Autofixture GuardClauseSertion在单元测试中引发System.BadImageFormatException异常

Unit testing 使用Autofixture GuardClauseSertion在单元测试中引发System.BadImageFormatException异常,unit-testing,idioms,autofixture,badimageformatexception,Unit Testing,Idioms,Autofixture,Badimageformatexception,我有一个使用xUnit、AutoFixture编写的单元测试,用于检查程序集类中的保护子句: [InlineData(typeof(ProjectOneClass))] [InlineData(类型(ProjectTwoClass))] [InlineData(类型(ProjectThreeClass))] [InlineData(类型(ProjectFourClass))] [InlineData(类型(ProjectFiveClass))] [理论(DisplayName=“类防止程序集中出

我有一个使用xUnit、AutoFixture编写的单元测试,用于检查程序集类中的保护子句:

[InlineData(typeof(ProjectOneClass))]
[InlineData(类型(ProjectTwoClass))]
[InlineData(类型(ProjectThreeClass))]
[InlineData(类型(ProjectFourClass))]
[InlineData(类型(ProjectFiveClass))]
[理论(DisplayName=“类防止程序集中出现空参数”)]
公共void guardagainstNullArgumentsAssemblys(类型assemblyHintType)
{
//安排
IFixture fixture=new fixture().Customize(new AutoMoqCustomization());
fixture.Behaviors.Add(新的TracingBehavior());
var断言=新的GuardClauseAssertion(fixture);
//断言
assertion.Verify(assemblyHintType.Assembly.GetTypes())
.其中(t=>
!t.Name.Equals(“MyWebServices”)&&
!t.Name.Equals(“MyComputer”)&&
!t.Name.Equals(“MyProject”)&&
!t.Name.Equals(“我的应用程序”)&&
!t.i接口&&
!t.IsGenericType&&
!t.IsCompilerGenerated()&&
!t.IsStaticClass()
));
}
我使用过滤器进行断言,以便将单元测试的焦点仅放在我编写的适当类上,并使用提示类型以特定程序集为目标。我使用
InlineData(typeof(…)
传递这些提示类型,因此每个提示类型只进行一次测试

测试通过了5个测试中的3个,在进行了几次测试运行之后,这些测试指出了我忘记放置空保护的代码,但其他两个测试产生了以下异常:

System.BadImageFormatException试图加载程序 格式不正确。(HRESULT的例外:0x8007000B)位于

System.Reflection.Emit.TypeBuilder.TermCreateClass(RuntimeModule模块,Int32 tk,ObjectHandleOnStack类型) 位于System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()的 位于的System.Reflection.Emit.TypeBuilder.CreateType() Ploeh.AutoFixture.Idioms.GuardClauseAssertion.autogenericalargument.get_Value() 在System.Linq.Enumerable.WhereSelectArrayIterator
2.MoveNext()中
System.Linq.Buffer
1..ctor(IEnumerable
1源代码)位于
System.Linq.Enumerable.ToArray(IEnumerable
1源代码)位于 Ploeh.AutoFixture.Idioms.GuardClauseAssertion.AutoGenericMethod.get_Value() 在 Ploeh.AutoFixture.Idioms.GuardClauseAssertion.Verify(MethodInfo-MethodInfo) 在 Ploeh.AutoFixture.Idioms.idiomaticsertion.Verify(MethodInfo[]methodInfos) 在Ploeh.AutoFixture.Idioms.idiomaticsertion.Verify(Type)at Ploeh.AutoFixture.Idioms.idiomaticsertion.Verify(Type[]types)位于 NullGuardTests.GuardAgainstNullArgumentsInNonModelAssembly(类型assemblyHintType) 在NullGuardTests.cs中:第58行

我将
TracingBehavior
添加到
iTexture
实例以获得更高的可见性,它显示:

请求:Infrastructure.Logging.IErrorAggregator errorAggregator
请求:Ploeh.AutoFixture.Kernel.seedRequest
。。。不停地,不停地

我已经查看了这个长跟踪中的第一个项目和最后一个项目,试图找出它们与成功测试跟踪中显示的第一个/最后一个项目的区别,但是我没有找到任何有意义的区别

我假设跟踪中的最后一项是异常之前
iTexture
中的最后一个活动

除了我目前所做的工作之外,我如何更清楚地了解这样的异常情况?

  • 每个目标程序集的目标都是.NET 4.0
  • 每个目标程序集在生成配置(AnyCPU)中具有相同的设置
  • 每个目标程序集都是用VB.NET编写的(尽管单元测试是用C#)
想法?先谢谢你

2014年3月29日更新


我仍然无法弄清楚这里发生了什么,但我希望把这个问题留给其他有同样问题的人,他们在这里发现了这个问题,这至少是一个理智的检查。如果工作负载允许,我将提交一份报告。

我对如何处理此错误没有任何具体想法,因为这不是AutoFixture中已知的错误。有没有一种简单的方法来重现这种行为?根据我的经验,
BadImageFormatException
通常是由兼容性或类似的一些基本问题引起的,很少有特定的代码段。。。我想说的是,这可能是一个框架问题,而不是AutoFixture的问题。然而,我并不经常遇到这种特殊的例外情况。并不是说我不想追究AutoFixture在这件事上的责任,而是说在这一点上,重做一次会很好。@MarkSeemann同意-重做一次会很好。我将仔细研究五个不同的VB.NET项目,并试图找出这三个没有抛出异常的项目的不同之处。可能有一些组件引用的差异。我还将看看是否可以创建一个简单的复制。