locked
How to Invoke Test methods in NSubstitute RRS feed

  • Question

  • User1081236289 posted

    Hi All,

    I am using NSubstitute to test my functions in my application.

    Now i have written the test methods for my functions. I dont no how to run this test methods.

    Can anyone tell me as how to run the test methods?

    For eg i have

    public interface ICalculator {
    int Add(int a, int b);
    string Mode { get; set; }
    }

    and i have used test method
    [Test]
    public void MyTestMethod() {
    var calculator = Substitute.For<ICalculator>();
    calculator.Add(1, 2).Returns(3);
    }

    Now how can i run the above test method in c# application

    thanks
    Gilli

    Monday, October 1, 2012 11:57 PM

All replies

  • User809840071 posted

    NSubstitute works with whatever testing framework you are currently using. The examples from the NSubstitute website all use NUnit, but you can also use XUnit, MBUnit, MSTest, etc. To run the NSubstitute examples unmodified try the Getting Started Guide on the NUnit website:

    http://nunit.org/index.php?p=getStarted&r=2.6.1

    If you are after more general information about automated testing in .NET you can try the links on the Microsoft ASP.NET/MVC page on Testing:

    http://www.asp.net/mvc/overview/testing

    Regards,
    David

    Tuesday, October 2, 2012 7:49 AM
  • User-1582127248 posted

    Assert.AreEqual(calculator.Add(1, 2), 3);

    or

    Assert.IsTrue(calculator.Add(1, 2).Return(3));

    Tuesday, September 15, 2015 8:26 AM
  • User-839818607 posted

    Assert.AreEqual(calculator.Add(1, 2), 3);

    Wednesday, October 7, 2015 8:34 AM