AutoFixture in F # UnitTest Project does not display unit tests in test explorer

I have a Visual Studio 2012 project and the following NuGet packages are installed:

  • AutoFixture with Auto Mocking using Moq
  • Autofixture with xUnit.net Data Theories
  • AutoFixture
  • Moq
  • xUnit.net: Extensions
  • xUnit.net: Runners
  • xUnit.net

Given the following contrived Logger class (Logger.fs):

namespace FUnit type public ILoggerContext = abstract member LogPath :string type public LoggerContext (logPath :string) = member val LogPath = logPath with get, set interface ILoggerContext with member this.LogPath = this.LogPath type public Logger () = member this.Log (context: ILoggerContext) value = System.String.Format("Logged {0} to {1}.", value, context.LogPath) 

and unit test:

 namespace FUnit.Test open FUnit type public Math_Add() = [<Xunit.Extensions.Theory>] [<Ploeh.AutoFixture.Xunit.AutoData>] member this.``Should Output Value And Path`` (path :string) = let context = new LoggerContext(path) let logger = new Logger() let expected = System.String.Format("Logged value to {0}.", path) let actual = logger.Log context "value" Xunit.Assert.Equal<string>(expected, actual) 

The tester does not recognize unit test after I demonstrate all the tests and build the project. The project is built correctly, without errors and warnings in the output logs of Build, General or Test.

If you replace the existing Theory and AutoData attributes with the Fact attribute, a test appears.

Is AutoFixture supported in F # test projects? Can anyone else reproduce this and find out what I'm doing wrong?

+4
source share
1 answer

I think this is a problem with conflicting versions of Xunit.Extensions used by Ploeh.Autofixture.Xunit and a test runner.

If you run tests using Xunit runners, you should see an exception complaining about the inability to find a specific version of Xunit.Extensions .

You can fix this by adding binding redirects to your app.config test projects. Since you are using NuGet, you can generate binding redirects by running this in the package manager console for your test project.

 Add-BindingRedirect 

You can then configure the generated binding redirects in app.config if you want.

After you rebuild the project, you will see that the test appears in VS Test Explorer.

+7
source

All Articles