Nunit test gives OneTimeSetUp result: no suitable constructor found

I have a problem when NUnit tells me: "No suitable constructor found." What causes this? I also get another message: "Exception does not have stacktrace". Both messages repeat over and over. Here is my code

[TestFixture]
public class SecurityServiceTests
{
    private IContext stubIContext;
    private ISecurityService securityService;
    private IWindsorContainer windsorContainer;

    public SecurityServiceTests(IContext stubIContext)
    {
        this.stubIContext= stubIContext;
    }

    [TestFixtureSetUp]
    public void TestSetup()
    {
        //Mocks the database context
        stubIContext= MockRepository.GenerateStub<IContext>();
        var returnedList = new List<string>();
        stubIContext.Stub(a => a.GetUserSecurities(null)).IgnoreArguments().Return(returnedList);

        securityService = new SecurityService(windsorContainer);

    }

    [Test]
    public void ControllerShouldGetUserGroupForCurrentUsers()
    {
        //Act
        var action = securityService.CurrentUserFeatureList;

        //Assert
        Assert.IsNotNull(action);
    }


}
+4
source share
2 answers

You are trying to create a parameterized device, so you have a constructor that takes one argument. Unlike the comment above, this is true for both NUnit V2 and V3.

, NUnit , , , . ,

[TestFixture(someArgument)]

, - , stubIContext TestFixtureSetUp. :

  • , .

  • , .

, , NUnit v3. , , , , .

, , . SetUp, TestFixtureSetUp. , , -, . , , , TestFixtureSetUp .

+5

SecurityServiceTests , TextFixture.

TextFixture:

, .

, NUnit .

, NUnit .

, , IContext stubIContext, .

public SecurityServiceTests(IContext stubIContext), .

: NUnit3, @Chris :

TestFixtureAttribute , .

, .

+3

All Articles