Testing a class library in C #

This is a very vague question (and noob), but ..... How can I get to testing class libraries in C #? I am using nUnit for testing.

What I'm trying to do is interact with databases. 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 output.

Hope this gives some insight. I was thinking of creating a test application that creates an instance of a library. Is there any other / better / more efficient approach I can take?

+5
source share
4 answers

, NUnit (TestFixture, Test ..). DLL Nunit.

, , (Arrange-Act-Assert )

-

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

unit test.

nUnit, xUnit MSTest ( Visual Studio).

+2

, :

 Solution (Your Application)
    + YourApplication.Library
    + YourApplication.WebApp
    + YourApplication.Tests

Tests - , . Unit Test , DLL NUnit, , . TestFixture Test, YourApplication.Library Assert .

+1

, .

  • NUnit, MBUnit MSTest
  • , , , . , , ( ). mock/stub, Moq Rhino.Mocks. , , .
  • If you feel like this, write a few more tests (they span the line between integration and unit tests, IMOs) that connect a real, but simple database with the same or similar schema as SQLite. Now your code no longer speaks to mocks, which you pre-programmed with your expectations, but it is also not suitable for a complete database.
  • Integration tests. Connect this thing to a real [non-production] database.
+1
source

All Articles