使用FsCheck的IndexOutOfRangeException

时间:2014-04-14 08:06:04

标签: fscheck

我刚刚开始使用FsCheck并且已经编写了一些简单的测试。但是我一直遇到一个问题,导致Xunit抛出异常然后杀死VS2012测试运行器(测试似乎永远运行)。

似乎任何返回非文字结果的尝试都会导致此异常。一些例子:

///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)

我通过NuGet安装了FsCheck.Xunit - FsCheck.Xunit的0.4.02版本,FsCheck的0.9.2.0版本和Xunit的1.9.2版本。我正在运行VS2012。我尝试使用相同的结果定位.Net版本4和4.5。

这是VS2012输出窗口的内容,但有例外:

  

------运行测试开始------   System.Reflection.TargetInvocationException:调用目标抛出了异常。 ---&GT; System.IndexOutOfRangeException:索引超出了数组的范围。     at Xunit.ExceptionUtility.GetStackTrace(IFailureInformation failureInfo,Int32 index)     在Xunit.Runner.VisualStudio.TestAdapter.VsExecutionVisitor.Visit(ITestFailed testFailed)     在Xunit.TestMessageVisitor.DoVisit [TMessage](IMessageSinkMessage消息,Func 2 callback) at Xunit.TestMessageVisitor.OnMessage(IMessageSinkMessage message) at Xunit.TestMessageVisitor 1.OnMessage(IMessageSinkMessage消息)     在Xunit.TestClassCallbackHandler.OnTest(XmlNode xml)     在Xunit.TestClassCallbackHandler.OnXmlNode(XmlNode xml)     在Xunit.XmlNodeCallbackHandler.System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent(String eventArgument)     在System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent(String eventArgument)     ---内部异常堆栈跟踪结束---     at System.RuntimeMethodHandle.InvokeMethod(Object target,Object [] arguments,Signature sig,Boolean constructor)     at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj,Object [] parameters,Object [] arguments)     在System.Reflection.RuntimeMethodInfo.Invoke(Object obj,BindingFlags invokeAttr,Binder binder,Object []参数,CultureInfo文化)     at Xunit.Sdk.ExecutorCallback.CallbackEventHandlerCallback.Notify(String value)     在Xunit.Sdk.Executor.OnTestResult(ITestResult结果,ExecutorCallback回调)     在Xunit.Sdk.Executor.RunTests。&lt;&gt; c__DisplayClass12。&lt; .ctor&gt; b__11(ITestResult结果)     在Xunit.Sdk.TestClassCommandRunner.Execute(ITestClassCommand testClassCommand,List 1 methods, Predicate 1 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) 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个方法,Predicate 1 startCallback, Predicate 1 resultCallback)     在Xunit.Sdk.Executor.RunTests。&lt;&gt; c__DisplayClass12。&lt; .ctor&gt; b__f()     在Xunit.Sdk.Executor.ThreadRunner(Object threadStart)     在System.Threading.ThreadHelper.ThreadStart_Context(对象状态)     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)     在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态)     在System.Threading.ThreadHelper.ThreadStart(Object obj)

测试用例看起来很好,我相信我一定会遗漏一些东西,但我看不清楚。有什么想法吗?

编辑:仅当在VS2012测试资源管理器中运行测试时才会发生这种情况。如果使用xUnit GUI运行,测试全部按预期工作。

0 个答案:

没有答案