AutoFixture with NUnit AutoMoq prevents tests from running

I am trying to use AutoFixture with NUnit and Moq using the following AutoMoqDataAttribute:

public class AutoMoqDataAttribute : AutoDataAttribute
{
    public AutoMoqDataAttribute()
        : base(new Fixture().Customize(new AutoMoqCustomization()))
    {
    }
}

      

But when I run this test:

[Test, AutoMoqData]
public void Test(Mock<IUser> user)
{
    // do stuff with user
}

      

The test never runs. AutomMoqData hits correctly, but the code inside the test is never executed and everything ends without warning with the following message:

Test adapter sent back a result for an unknown test case. Ignoring result for 'Test(Mock<Sandbox.IUser>)'

      

The test also does not appear in the list of test runs.

But if I remove the parameter:

[Test, AutoMoqData]
public void Test()
{
    // do stuff without user
}

      

Everything works fine, but it is less useful without passed parameters :)

Did I miss something?

Here is a list of Nuget package versions:

<package id="AutoFixture" version="3.50.2" targetFramework="net452" />
<package id="AutoFixture.AutoMoq" version="3.50.2" targetFramework="net452" />
<package id="AutoFixture.NUnit3" version="3.50.2" targetFramework="net452" />
<package id="Moq" version="4.5.3" targetFramework="net452" />
<package id="NUnit" version="3.7.1" targetFramework="net452" />

      

EDIT: Following @MarkSeemann's advice, I've filed a bug on Github .

+3


source to share


1 answer


Visual Studio Test Player

This looks like an issue with the NUnit Visual Studio test adapter. I can reproduce the problem when I also add NUnit3TestAdapter to my replication solution.

I also assume that the test class has an attribute [TestFixture]

so that the entire replay class looks like this:

[TestFixture]
public class Tests
{
    [Test, AutoMoqData]
    public void Test(Mock<IUser> user)
    {
        Assert.NotNull(user);
    }
}

      

When I try to run all tests with the Visual Studio 2015 test runner, the test never runs and this is the result of checking the output window:

------ Run test started ------
NUnit Adapter 3.7.0.0: Test execution started
Running all tests in C:\Users\mark\Documents\Stack Overflow\44564377\44564377\bin\Debug\Ploeh.StackOverflow.Q44564377.dll
NUnit3TestExecutor converted 1 of 1 NUnit test cases
NUnit Adapter 3.7.0.0: Test execution complete
Test adapter sent back a result for an unknown test case. Ignoring result for 'Test(Mock<Ploeh.StackOverflow.Q44564377.IUser:8e33>)'.
========== Run test finished: 0 run (0:00:01,1763498) ==========

      

TestDriven.Net

If, on the other hand, I try to run it from TestDriven.Net , it works just fine:



------ Test started: Assembly: Ploeh.StackOverflow.Q44564377.dll ------

1 passed, 0 failed, 0 skipped, took 0,79 seconds (NUnit 3.7.1).

      

TestDriven.Net is sometimes unusually tolerant of small bugs in your test code, so it might not be that in and of itself.

NUnit 3 Console

Since TestDriven.Net may be too liberal in what it takes, the best test would be to try it with the official NUnit 3 console runner :

$ packages/NUnit.ConsoleRunner.3.6.1/tools/nunit3-console.exe 44564377/bin/Debug/Ploeh.StackOverflow.Q44564377.dll
NUnit Console Runner 3.6.1
Copyright (C) 2017 Charlie Poole

Runtime Environment
   OS Version: Microsoft Windows NT 10.0.15063.0
  CLR Version: 4.0.30319.42000

Test Files
    44564377/bin/Debug/Ploeh.StackOverflow.Q44564377.dll


Run Settings
    DisposeRunners: True
    WorkDirectory: C:\Users\mark\Documents\Stack Overflow\44564377
    ImageRuntimeVersion: 4.0.30319
    ImageTargetFrameworkName: .NETFramework,Version=v4.6.1
    ImageRequiresX86: False
    ImageRequiresDefaultAppDomainAssemblyResolver: False
    NumberOfTestWorkers: 4

Test Run Summary
  Overall result: Passed
  Test Count: 1, Passed: 1, Failed: 0, Warnings: 0, Inconclusive: 0, Skipped: 0
  Start time: 2017-06-15 11:09:21Z
    End time: 2017-06-15 11:09:22Z
    Duration: 0.933 seconds

Results (nunit3) saved as TestResult.xml

      

This also succeeds in the test.

Intermediate withdrawal

Since both the official console runner and TestDriven.Net are running the test successfully, I would tentatively deduce that this looks like a defect in the NUnit3TestAdapter package. May I suggest a problem for you?

+6


source







All Articles