2

I'm using NUnit with AutoFixture, AutoMoq and the Theory attribute.

Here is my test method,

[TestFixture]
public class TestClass
{
    [Theory, AutoMoqData]
    public void TestI(I i)
    { }

}

the interface

public interface I
{ }

and the attribute

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

When I build my solution the test is discovered. When I run the test the following is written to the Output window:

NUnit 1.0.0.0 executing tests is started
Run started: [...].Test.dll
NUnit 1.0.0.0 executing tests is finished
Test adapter sent back a result for an unknown test case. Ignoring result for 'TestI(Mock<TestClass+I:1393>.Object)'.

When using xUnit.net the above test is run correctly. Why is not it working with NUnit?


I have the following Nuget packages installed in the test project:

  • AutoFixture 3.18.1
  • AutoFixture.AutoMoq 3.18.1
  • Moq 4.2.1402.2112
  • NUnit 2.6.3
  • NUnitTestAdapter 1.0

I'm running the test from within Visual Studio 2013 Professional. I also tried running the test in the separate GUI runner, with the same result.

MEMark
  • 1,493
  • 2
  • 22
  • 32

1 Answers1

3

The following NUnit test passes in Visual Studio 2013 with the TestDriven.Net add-in:

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

public interface IInterface
{ 
}

public class Tests
{
    [Test, AutoMoqData]
    public void IntroductoryTest(IInterface i)
    {
        Assert.NotNull(i);
    }
}

The built-in test runner doesn't discover the above test. This looks like a bug in the test runner.

Nikos Baxevanis
  • 10,868
  • 2
  • 46
  • 80
  • Interesting! I will try TestDriven.Net. But as I mention above, my test doesn't work in the stand-alone NUnit runner either. Your test is probably not discovered because you're missing `TestFixture` on the class. I also notice you're using `Test` rather than `Theory`, is that for a reason? – MEMark Apr 09 '14 at 22:48
  • The attribute usage comes from the sample code that is generated once you install the NuGet package. – Nikos Baxevanis Apr 10 '14 at 00:33
  • Now I've tried your example. As you mention it runs fine in TestDriven.Net. You are also correct regarding the attributes, [TestFixture] is no longer required. http://www.nunit.org/index.php?p=testFixture&r=2.5 Apart from that this unfortunately doesn't solve my problem, since I need the tests to be run using the NUnit runner on my build server. – MEMark Apr 10 '14 at 06:12
  • Most (if not all) online information about AutoFixture.NUnit2 can be found [here](http://gertjvr.wordpress.com/category/autofixture/) and [here](http://madstt.dk/nunit-support-for-autofixture/). If you can't find a solution for the build server from these URLs you may [open an issue](https://github.com/AutoFixture/AutoFixture/issues/new) at the AutoFixture project site. – Nikos Baxevanis Apr 10 '14 at 09:25
  • Thanks, but I have no problem with my build server. Everything works ok there. I'm just mentioning it to explain why switching to TestDriven.Net is not an option. – MEMark Apr 10 '14 at 11:26
  • Thanks for the link to AutoFixture. I will post an issue there as well. – MEMark Apr 10 '14 at 11:43