I'm new to unit testing and would like to know how to properly mock out an interface using JustMock Lite. I have class that looks something like this :
public class Person
{
public Person(IFileReader reader)
{
Parse(reader);
}
public string Name {get; private set;}
public uint Age {get; private set;}
private void Parse(IFileReader reader)
{
Name = reader.ReadString();
Age = reader.ReadUInt();
}
}
I have created a test method like so
[TestMethod]
public void GetAgeReturnsCorrectValue()
{
// arrange
var reader = Mock.Create<IFileReader>();
var person= new Person(reader);
// act
var age = person.Age;
// assert
Assert.AreEqual(age, ???);
}
What is the proper way to write this unit test?
You should write the arrange part of your test. I haven't used JustMock but from the examples I guess it should be something like this:
and then your test becomes:
You arrange what is to return and assert it is indeed returned.