2

I'm trying to write some unit tests in F# with xUnit2 and AutoFixture and I'm facing a problem. I have a Theory with custom attributes that inherits from InlineAutoData and the Test Explorer keeps saying me that no tests was found. If I replace the Theory attribute by a Fact attribute it still doesn't work but if I remove the custom InlineData attributes the test is discovered. Tests are written in F# but attributes are in C# in another project.

I have found this StackOverflow question which seems similar but it doesn't help me solving my problem : AutoFixture in F# UnitTest Project Not Displaying Unit Tests in Test Explorer

Here is the unit test declaration:

[<Theory>]
[<SyntaxTreeInlineAutoData("Class/SingleClass.cs", 1)>]
[<SyntaxTreeInlineAutoData("Class/MultipleClass.cs", 2)>]
[<SyntaxTreeInlineAutoData("Class/NestedClass.cs", 2)>]
let ``Inspect_WhenVariousContexts_WithSuccess`` (count, tree : SyntaxTree) = 

Here is attributes declarations:

[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class SyntaxTreeInlineAutoDataAttribute : InlineAutoDataAttribute
{
    #region Constructors

    public SyntaxTreeInlineAutoDataAttribute(string sourceFile, params object[] values) 
        : base(new SyntaxTreeAutoDataAttribute(sourceFile), values)
    {
    }

    #endregion
}

[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class SyntaxTreeAutoDataAttribute : AutoDataAttribute
{
    #region Constructors

    public SyntaxTreeAutoDataAttribute() : this(null)
    {
    }

    public SyntaxTreeAutoDataAttribute(string sourceFile) 
        : base(new Fixture().Customize(new SyntaxTreeCustomization(sourceFile)))
    {
    }

    #endregion
}

[Edit]

The project is a port of a C# project. Unit tests was working fine with the custom attribute. The bug only occurred with tests write in F#.

Everything is installed : xUnit2, xUnit.runners.visualstudio and AutoFixture.

Thanks for the help.

Community
  • 1
  • 1
Julien Pires
  • 512
  • 7
  • 18
  • Do you have any C# tests that do get discovered? Have you installed xUnit Visual Studio runner? – Fyodor Soikin Apr 29 '16 at 16:39
  • My [self-answered semi-related question](http://stackoverflow.com/questions/35103781/why-is-the-visual-studio-2015-test-runner-not-discovering-my-xunit-v2-tests/35103782#35103782) was with F#, xUnit and VS2015 (but not with AutoFixture) – Ruben Bartelink Apr 29 '16 at 18:04

1 Answers1

1

I could reproduce this issue, and in my repro at least, the problem was a versioning conflict. Most Visual Studio test runners don't tell you that, but if you attempt to run the unit tests with a command-line runner, you'll see the actual error reported.

In my repro, I solve the problem by adding the following app.config file to my F# project:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="xunit.core" publicKeyToken="8d05b1bb7a6fdb6c" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.0.3179" newVersion="2.1.0.3179" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
Mark Seemann
  • 225,310
  • 48
  • 427
  • 736
  • Thanks for the quick answer. It works fine with the appconfig. Next time I have a problem, I will try to launch tests from the command line. – Julien Pires Apr 29 '16 at 20:43