Testing a Class Library in C#

c#, nunit, visual-studio-2010

Solution

You have to create a separate project that uses NUnit's data annotations (`TestFixture`, `Test`, etc). Then you can build that project and load the created DLL into Nunit.

As far as the tests, just write them as you would normally (Arrange-Act-Assert is the more prevalent pattern)

Something like this

[Test]
public void MethodName_CallDatabase_ObjectDeserialized()
{
    //Arrange
    var db = new db();
    //Act 
    var output = db.ExecuteCall();
    //Assert
    Assert.That(output, Is.EqualTo("123"));
}

Problem

This is a very vague (and noob) question, but.....How would one approach testing a class library in C#? I am using nUnit for testing. What I am trying to do is test database interaction. The input will be a serialized XML object, deserialize it to test it against the code, then the XML object will be re-serialized and outputted. Hopefully, this gives some insight. I had thought about creating a test app that creates an instance of the library. Is there a different/better/more efficient approach I can take?

Original source