I have to perform a series of unit tests, and I'm just starting and I'm not sure how to do them.
I have an interface IPersona
with some methods, and the one I am testing is this:
string nombreCompleto();
And the class Persona
is like this:
private string nombre;
private string apellido;
private int edad;
private int kmRecorridos;
private bool vivo;
private Persona pareja;
public Persona()
{
this.nombre = "";
this.apellido = "";
this.edad = 0;
this.kmRecorridos = 0;
this.pareja = null;
nacer();
}
public Persona(string n, string a, int e)
{
this.nombre = n;
this.apellido = a;
this.edad = e;
this.pareja = null;
this.kmRecorridos = 0;
nacer();
}
public string nombreCompleto()
{
return "Nombre Completo: " + this.nombre + " " + this.apellido;
}
I am doing the test in the following way, but I have tried some things and I don't know how to make it successful:
[TestMethod]
public void TestMethod1()
{
var mockPersona = new Mock<IPersona>();
mockPersona.Setup(x => x.nombreCompleto()).Returns("Nombre completo " + "" + " " + "");
IPersona persona = (IPersona) new Persona();
Assert.AreEqual(persona.nombreCompleto(), ((IPersona) mockPersona.Object).nombreCompleto());
}
Already solved. He had a little bug where
.Setup()
the string he was passing to him was not spelled correctly.On the other hand, I have performed the test in another way:
And so it has worked. I hope it helps with future problems.