Hi I have created a class which has a method to return a string "HelloWorld"
Here is the code
public class Class1
{
public string GetHelloWorld()
{
return "HelloWorld";
}
}
I have written a NUnit Test case and want to mock the return string for this method as below
public class UnitTest1
{
Mock<Class1> mock;
[Test]
public void TestMethod1()
{
string expected = "Hi";
mock.Setup(m => m.GetHelloWorld()).Returns(()=>"Hi");
Class1 obj = new Class1();
string x=obj.GetHelloWorld();
Assert.AreEqual("Hi", x);
}
}
When I am running with Nunit,I am getting the error as "Object reference not set to an instance of an object" on line 15 which is mock.setup
Can anybody help me in resolving this issue to make this unit test pass.
Thanks for your help on this.