question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issues with custom arbitraries when running tests on NCrunch and TFS.

See original GitHub issue

Hello, I am having really inconsistent behaviour when running on the following test runners:

  • TFS
  • NCrunch

However, the Resharper test runner is fine.

What the 2 runners that are failing have in common is that they are running tests in parallel in separate processes and the R# runner is running the tests in a single process, AFAIK.

The exception:

Exception during test
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
   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 FsCheck.Runner.checkMethod(Config config, MethodInfo m, FSharpOption`1 target)
   at Xunit.Sdk.ExecutionTimer.Aggregate(Action action)
   at <StartupCode$FsCheck-Xunit>.$PropertyAttribute.testExec@187(PropertyTestCase this, IMessageBus messageBus, Object[] constructorArguments, CancellationTokenSource cancellationTokenSource, XunitTest test, RunSummary summary, TestOutputHelper outputHelper, Unit unitVar0)
System.Exception: The type UnitsNet.Length is not handled automatically by FsCheck. Consider using another type or writing and registering a generator for it.
   at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1379.Invoke(String message)
   at FsCheck.ReflectArbitrary.reflectGenObj@129.Invoke(Type t)
   at FsCheck.Common.f@1[a,b](IDictionary`2 memo, FSharpFunc`2 f, a n, Unit _arg1)
   at FsCheck.Common.memoizeWith[a,b](IDictionary`2 memo, FSharpFunc`2 f, a n)
   at FsCheck.Arb.Derive@1138.get_Generator()
   at FsCheck.Arbitrary`1.FsCheck-IArbitrary-get_GeneratorObj()
   at FsCheck.ReflectArbitrary.gs@64.GenerateNext(IEnumerable`1& next)
   at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.MoveNextImpl()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at Microsoft.FSharp.Collections.SeqModule.ToArray[T](IEnumerable`1 source)
   at FsCheck.ReflectArbitrary.productGen@63[a](FSharpFunc`2 getGenerator, IEnumerable`1 ts, FSharpFunc`2 create)
   at FsCheck.ReflectArbitrary.reflectObj(FSharpFunc`2 getGenerator, Type t)
   at FsCheck.ReflectArbitrary.reflectGenObj@129.Invoke(Type t)
   at FsCheck.Common.f@1[a,b](IDictionary`2 memo, FSharpFunc`2 f, a n, Unit _arg1)
   at FsCheck.Common.memoizeWith[a,b](IDictionary`2 memo, FSharpFunc`2 f, a n)
   at FsCheck.Arb.Derive@1138.get_Generator()
   at FsCheck.Testable.forAll[a,b](Arbitrary`1 arb, FSharpFunc`2 body)
   at FsCheck.Runner.check[a](Config config, a p)

or

System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
---- System.Exception : The type AwtSG.Domain.NavigationUtilities.Latitude is not handled automatically by FsCheck. Consider using another type or writing and registering a generator for it.
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 System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at FsCheck.Runner.checkMethod(Config config, MethodInfo m, FSharpOption`1 target)
at <StartupCode$FsCheck-Xunit>.$PropertyAttribute.testExec@187(PropertyTestCase this, IMessageBus messageBus, Object[] constructorArguments, CancellationTokenSource cancellationTokenSource, XunitTest test, RunSummary summary, TestOutputHelper outputHelper, Unit unitVar0)
----- Inner Stack Trace -----
at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1379.Invoke(String message)
at FsCheck.ReflectArbitrary.reflectGenObj@129.Invoke(Type t)
at FsCheck.Common.f@1[a,b](IDictionary`2 memo, FSharpFunc`2 f, a n, Unit _arg1)
at FsCheck.Common.memoizeWith[a,b](IDictionary`2 memo, FSharpFunc`2 f, a n)
at FsCheck.Arb.Derive@1138.get_Generator()
at FsCheck.Arbitrary`1.FsCheck-IArbitrary-get_GeneratorObj()
at FsCheck.ReflectArbitrary.gs@64.GenerateNext(IEnumerable`1& next)
at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.MoveNextImpl()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at Microsoft.FSharp.Collections.SeqModule.ToArray[T](IEnumerable`1 source)
at FsCheck.ReflectArbitrary.productGen@63[a](FSharpFunc`2 getGenerator, IEnumerable`1 ts, FSharpFunc`2 create)
at FsCheck.ReflectArbitrary.reflectObj(FSharpFunc`2 getGenerator, Type t)
at FsCheck.ReflectArbitrary.reflectGenObj@129.Invoke(Type t)
at FsCheck.Common.f@1[a,b](IDictionary`2 memo, FSharpFunc`2 f, a n, Unit _arg1)
at FsCheck.Common.memoizeWith[a,b](IDictionary`2 memo, FSharpFunc`2 f, a n)
at FsCheck.Arb.Derive@1138.get_Generator()
at FsCheck.Testable.forAll[a,b](Arbitrary`1 arb, FSharpFunc`2 body)
at FsCheck.Runner.check[a](Config config, a p)

(The second one is taken from a TFS build of a different project)

A minimum working example, which I can reproduce the error with consistently is below.

The .cs file:

using FsCheck;
using FsCheck.Xunit;
using UnitsNet;
using Xunit;

namespace FsCheckNcrunchExample
{
    public class UnitTest1
    {
        public class Arbitraries
        {
            public static Arbitrary<Length> Lengths()
                => Arb.Default.Float()
                    .Filter(i => i > 0 && i < 100)
                    .Convert(Length.FromMeters, i => i.Meters);
        }

        static UnitTest1()
        {
            Arb.Register<Arbitraries>();
        }

        [Property]
        public void Test1(Length a, Length b)
        {
            Assert.True(true);
        }

        [Property]
        public void Test2(Length a, Length b)
        {
            Assert.True(true);
        }

        [Property]
        public void Test3(Length a, Length b)
        {
            Assert.True(true);
        }

        [Property]
        public void Test4(Length a, Length b)
        {
            Assert.True(true);
        }
    }
}

The project file:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>

    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170425-07" />
    <PackageReference Include="xunit" Version="2.2.0" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
    <PackageReference Include="FsCheck.Xunit" Version="*" />
    <PackageReference Include="UnitsNet" Version="*" />
  </ItemGroup>

</Project>

The dependency tree in Visual Studio: capture

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kurtschelfthoutcommented, Sep 27, 2017

Going to close this as the issue is resolved, please don’t let that stop you from contributing an example or even better documentation!

1reaction
aignascommented, Sep 25, 2017

Actually, if I register the arbitraries in the non static constructor, then it is working more reliably. Actually, on NCrunch for my example project it has not failed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problems using FsCheck arbitraries - Build/Test Issues
Hello, I have some problems, when using Arbitraries from the FsCheck package. I am not sure if this is a problem in NCrunch...
Read more >
Test And Runtime Related Issues - NCrunch Documentation
Another common cause for test failures is where custom builds (or build steps) are being used to produce artifacts required for the runtime...
Read more >
MSBuild does not run tests using NCrunchRunner project
I have a special build configuration created for TFS called "Server Build" and all projects are disabled for build except the NCrunchRunner ...
Read more >
NCrunch is not seeing some tests - Build/Test Issues
The strange thing is that some tests within the same project do show up and run, but other tests do not. Back to...
Read more >
Tests Not DIsplayed - Build/Test Issues
I have Show Passing Tests and Show Failing Tests selected. If I change a TestCase value NCrunch appears to automatically run the test...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found