我有很多实例和属性,我想使用XUnit进行验证。
myInstance.SomeProperty1.Should().HaveCount(2);
myInstance.SomeProperty2.Should().HaveCount(2);
[...]
myInstance.SomePropertyN.Should().HaveCount(2);
当此断言失败时,它们会抛出以下异常
Xunit.Sdk.XunitException
Expected collection to contain 2 item(s), but found 0.
at FluentAssertions.Execution.XUnit2TestFramework.Throw(String message)
at FluentAssertions.Execution.AssertionScope.FailWith(String message, Object[] args)
at FluentAssertions.Collections.SelfReferencingCollectionAssertions`2.HaveCount(Int32 expected, String because, Object[] becauseArgs)
at [...]
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Xunit.Sdk.TestInvoker`1.<>c__DisplayClass48_1.<<InvokeTestMethodAsync>b__1>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Xunit.Sdk.ExecutionTimer.<AggregateAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Xunit.Sdk.ExceptionAggregator.<RunAsync>d__9.MoveNext()
到目前为止,一切都很好。但是,如何使异常更有意义?我想查看断言失败的属性的名称。
问题是,这是相当大的对象,测试的分解通常要花费一些时间。知道测试失败的属性可以加快我的测试过程。预先感谢!