Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug a class library in Visual Studio

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?

like image 525
PICyourBrain Avatar asked Jan 08 '10 13:01

PICyourBrain


People also ask

How do I debug a string library in Visual Studio Code?

Instead of starting the ShowCase app project, right-click the StringLibraryTests project, and select Debug Tests from the context menu. Visual Studio starts the test project with the debugger attached. Execution will stop at any breakpoint you've added to the test project or the underlying library code.

How to create a class library project in Visual Studio?

In the Name text box, enter "StringLibrary" as the name of the project. Select OK to create the class library project. The code window then opens in the Visual Studio development environment.

How to debug a class library in a web application?

If you do not know how to debug a class library in a web application, here are the steps: Enable debugging on the web application. Deploy a debug version of the class library with breakpoints. Attach Visual Studio (debugger) with the ASP.NET worker process.

How do I enable debuggable attribute in Visual Studio?

To set DebuggableAttribute: Select the C++ DLL project in Solution Explorer and select the Properties icon, or right-click the project and select Properties. In the Properties pane, under Linker > Debugging, select Yes (/ASSEMBLYDEBUG) for Debuggable Assembly.


2 Answers

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.

like image 157
mdm Avatar answered Sep 27 '22 01:09

mdm


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.

like image 42
Joe Avatar answered Sep 26 '22 01:09

Joe