问题
I have just started working with FsCheck and have been writing some simple tests. However I keep coming across an issue which causes Xunit to throw an exception which then kills the VS2012 test runner (tests appear to run forever).
It seems as though any attempt to return a non-literal result causes this exception. Some examples:
///This will work, the test will trivially succeed and the result values
///will be available in the "test output" screen in VS2012's test explorer.
let [<Property>] ``Test case #1`` (x : Int32) =
(x > 3) ==>
let result = (x > 5)
printfn "Result = %O" result
true
///This will cause the IndexOutOfRangeException which kills xUnit, causing the test
///to "run" until cancelled in VS2012's test explorer.
let [<Property>] ``Test case #2`` (x : Int32) =
(x > 3) ==>
(x > 5)
///This also kills xUnit.
let [<Property>] ``Test case #3`` (x : Int32) =
(x > 5)
I installed FsCheck.Xunit via NuGet - version 0.4.02 of FsCheck.Xunit, 0.9.2.0 of FsCheck and 1.9.2 of Xunit. I am running VS2012. I've tried targeting both .Net versions 4 and 4.5 with the same result.
Here is the contents of the VS2012 output window with the exception:
------ Run test started ------ System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IndexOutOfRangeException: Index was outside the bounds of the array. at Xunit.ExceptionUtility.GetStackTrace(IFailureInformation failureInfo, Int32 index) at Xunit.Runner.VisualStudio.TestAdapter.VsExecutionVisitor.Visit(ITestFailed testFailed) at Xunit.TestMessageVisitor.DoVisit[TMessage](IMessageSinkMessage message, Func
2 callback) at Xunit.TestMessageVisitor.OnMessage(IMessageSinkMessage message) at Xunit.TestMessageVisitor
1.OnMessage(IMessageSinkMessage message) at Xunit.TestClassCallbackHandler.OnTest(XmlNode xml) at Xunit.TestClassCallbackHandler.OnXmlNode(XmlNode xml) at Xunit.XmlNodeCallbackHandler.System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent(String eventArgument) at System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent(String eventArgument) --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Xunit.Sdk.ExecutorCallback.CallbackEventHandlerCallback.Notify(String value) at Xunit.Sdk.Executor.OnTestResult(ITestResult result, ExecutorCallback callback) at Xunit.Sdk.Executor.RunTests.<>c__DisplayClass12.<.ctor>b__11(ITestResult result) at Xunit.Sdk.TestClassCommandRunner.Execute(ITestClassCommand testClassCommand, List1 methods, Predicate
1 startCallback, Predicate1 resultCallback) at Xunit.Sdk.Executor.RunTests.<>c__DisplayClass12.<.ctor>b__f() at Xunit.Sdk.Executor.ThreadRunner(Object threadStart) at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart(Object obj) Index was outside the bounds of the array. at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Xunit.Sdk.ExecutorCallback.CallbackEventHandlerCallback.Notify(String value) at Xunit.Sdk.Executor.OnTestResult(ITestResult result, ExecutorCallback callback) at Xunit.Sdk.Executor.RunTests.<>c__DisplayClass12.<.ctor>b__11(ITestResult result) at Xunit.Sdk.TestClassCommandRunner.Execute(ITestClassCommand testClassCommand, List
1 methods, Predicate1 startCallback, Predicate
1 resultCallback) at Xunit.Sdk.Executor.RunTests.<>c__DisplayClass12.<.ctor>b__f() at Xunit.Sdk.Executor.ThreadRunner(Object threadStart) at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart(Object obj)
The test cases look fine to me, I am sure I must be missing something but I cannot see what. Any ideas?
Edit: This only occurs when the tests are run in the VS2012 test explorer. The tests all work as expected if run using the xUnit GUI.
来源:https://stackoverflow.com/questions/23055005/indexoutofrangeexception-using-fscheck