Search code examples
nsubstitute

It looks like nSubsitute is just testing itself rather than my code


Possibly stupid question. In the docs they give this example

calculator.Add(1, 2).Returns(3);
Assert.That(calculator.Add(1, 2), Is.EqualTo(3));

Am I testing that the actual calculator returns 3 or just that the substitute does? If the latter, what is the point?


Solution

  • I'm not sure where my brain went, but I seem to have momentarily lost the point of a mock. Saying

    calculator.Add(1, 2).Returns(3)
    

    is the wrong example. A much better example would be

    var person = database.GetMember(123) returns "Jesse Liberty"
    

    not so that I can test the mock, but so that I can test code that depends on the database.

    Obvious, I know, but sometimes the brain just shuts down.