I am currently writing unit tests that uses methods from one of my mocked interfaces. Everything works fine, but when I add a new method to the interface (the connection between the interface and its base class is fine), the mocked interface in my unit test project does not pick up the new method, throwing a "method not defined" error. Here is a basic example of how I am adding new methods.
Base Class:
namespace MyProject.Business
{
public class MyProjectValidator: IValidator
{
private readonly IValidator mValidator;
public MyProject(IValidator validator)
{
this.mValidator= validator;
}
public bool myMethod()
{
return true;
}
public bool myNewMethod()
{
return true;
}
}
}
Interface
namespace MyProject.Business
{
public interface IValidator
{
bool myMethod(string input);
bool myNewMethod (string input);
}
}
Unit Tests (different project, same solution)
using MyProject.Business;
namespace MyProject.Tests.Business
{
[TestClass]
public class MyProjectTests
{
[TestMethod]
public void testMethods()
{
var testValidator= new Mock<IValidator>();
var testMyProject= new MyProject(testValidator.Object);
var testOld = testValidator.myMethod(); // testOld = true
var testNew = testValidator.myNewMethod(); // error: myNewMethod() not defined
}
}
}
As I commented above, my newly added method is not being recognized. My old method was created before the unit test project was created (I assume, I am inheriting code from a former developer). I tried checking the references in the unit test project for a failed linkage but all of the functions of IValidator appear. I have tried rebuilding and restarting & rebuilding both the solution and the project to no avail.
Any guidance concerning why "myNewMethod()" is not being recognized in my unit test project would be appreciated.
Update: added the using line as requested.
Aucun commentaire:
Enregistrer un commentaire