How to debug a class library in Visual Studio

35,263

Solution 1

You could add a testing project to your current solution, then set that project as the startup project. Then, hitting F5 on your class library project will start your testing project.

Solution 2

Take a look at NUnit or other similar unit testing framework.

The "Team Developer" and "Team Suite" flavors of Visual Studio already have Microsoft's unit testing framework built in.

Solution 3

Create a unit test project for the class library by using the right-click "Create Unit Tests" in a class/method in the library. I would recommend downloading TestDriven.NET and using the right-click test runner in it.

Solution 4

Are you talking about unit tests? You can use something like nUnit or the built in testing framework that comes with Visual Studio. The simplest tests just require you to add some attributes to your test fixture and make an assertion like obj1 == obj2.

Checking out something like Test-Driven Development (TDD), Domain-Driven Development (DDD) or Behavioral-Driven Development (BDD) may be beneficial. I like to use nUnit with nBehave, myself.

Share:
35,263
PICyourBrain
Author by

PICyourBrain

Electrical Engineer, Software Developer, Tinkerer

Updated on July 30, 2022

Comments

  • PICyourBrain
    PICyourBrain almost 2 years

    I am working on a class library (DLL) project in Visual Studio 2008; programming in C#. In order to test my DLL I just created a second project that is a console application and in that project I can reference the first and run tests. Is there a simpler way of doing this? Can I just create another file within my class library project that has the tests in it and then somehow tell Visual Studio to run that file?

    I know one way would be to add a text file to my project and then write my test code in JScript. Then in the Project settings on the debug menu I can tell it to Start External Program (JScript). Then, the name of my test file, test.js, goes in the Command Line Arguments box. But, I am wondering if there is a way to do it using C# code instead of JScript?

  • Mark Seemann
    Mark Seemann over 14 years
    +1 In addition, if you ever get into the habit of doing Test-Driven Development, you are likely to find that you will be needing to debug a lot less.
  • Jamie Keeling
    Jamie Keeling over 14 years
    Supplementary to Joe's answer, this link should hopefully set you in the right direction as it will show you how to create and run tests with NUnit. en.csharp-online.net/…