Search code examples
c#testingnunitassertassertions

What is the pattern for testing void functions with NUnit?


I want to add a Test for a void method, and got this far:

[Test]
public void TestDuckbilledPlatypusInterface()
{
    var dbPlatypus = IOC.container.Resolve<IDuckbilledPlatypus>();

    dbPlatypus.InsertIntoPoisonousFoot(HttpWebRequest httpwebreq);

    Assert.? <= assert what? or what?
}

What can I assert in this case - just that it ran without throwing an exception? If so, what is the received methodology for doing that?


Solution

  • Testing for "no exception thrown" is of some value, but I would try to also test for possible side effects from the void method. (Properties set etc).

    If this is a repository method it might actually be more valuable to write an integration test instead where you test that the correct row was inserted into the database.