Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot debug a unit testing project in Visual Studio 2012

I couldn't find a post similar to this, so I hope this isn't a duplicate.

I have a c# class library that I'm trying to run unit tests on in Visual Studio 2012. I've added a new Unit Test Project to my solution, and added my main project as a reference there. I've set my unit test project as the Startup Project. When I try to debug, I get an error message

A project with an Output Type of Class Library cannot be started directly.

In order to debug this project, add an executable project to this solution which references the library project. Set the executable project as the startup project.

enter image description here

According to the walkthrough at msdn, it should be running the tests when I hit debug. Any thoughts? Here is my unit test code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.VisualStudio.TestTools.UnitTesting;
using Common;
using Messages;

namespace MessageUnitTests
{
    [TestClass]
    class RegistrationTester
    {
        [TestMethod]
        public void RegistrationRequest_TestConstructorsAndFactories()
        {
            RegistrationRequest rr1 = new RegistrationRequest("myhandle");
            Assert.AreEqual("myhandle", rr1.Handle);

            rr1 = new RegistrationRequest("longHandle-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789'|;:',.=-_+!@#$%^&*()");
            Assert.AreEqual("longHandle-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789'|;:',.=-_+!@#$%^&*()", rr1.Handle);

            rr1 = new RegistrationRequest("");
            Assert.AreEqual("", rr1.Handle);

            rr1 = new RegistrationRequest(null);
            Assert.AreEqual(null, rr1.Handle);

            rr1 = new RegistrationRequest("myhandle");
            ByteList bytes = new ByteList();
            rr1.Encode(bytes);

            RegistrationRequest rr2 = RegistrationRequest.Create(bytes);
            Assert.IsNotNull(rr2);
            Assert.AreEqual(rr1.IsARequest, rr2.IsARequest);
            Assert.AreEqual(rr1.MessageNr.ProcessId, rr2.MessageNr.ProcessId);
            Assert.AreEqual(rr1.MessageNr.SeqNumber, rr2.MessageNr.SeqNumber);
            Assert.AreEqual(rr1.ConversationId.ProcessId, rr2.ConversationId.ProcessId);
            Assert.AreEqual(rr1.ConversationId.SeqNumber, rr2.ConversationId.SeqNumber);
            Assert.AreEqual(rr1.RequestType, rr2.RequestType);
            Assert.AreEqual(rr1.SessionId, rr1.SessionId);
            Assert.AreEqual(rr1.Handle, rr2.Handle);
        }

        //[TestMethod]
        //public void RegistrationRequest_EncodingDecoding()
        //{
        //    Message m1 = new RegistrationRequest("myhandle");
        //    m1.MessageNr = MessageNumber.Create(10, 14);
        //    m1.ConversationId = MessageNumber.Create(10, 12);
        //    ByteList bytes = new ByteList
        //}
    }
}
like image 496
Matt Avatar asked Sep 26 '12 03:09

Matt


People also ask

How do you Debug a unit test project?

To start debugging: In the Visual Studio editor, set a breakpoint in one or more test methods that you want to debug. Because test methods can run in any order, set breakpoints in all the test methods that you want to debug. In Test Explorer, select the test method(s) and then choose Debug on the right-click menu.

Why are my breakpoints not working?

If a source file has changed and the source no longer matches the code you're debugging, the debugger won't set breakpoints in the code by default. Normally, this problem happens when a source file is changed, but the source code wasn't rebuilt. To fix this issue, rebuild the project.

How do I enable debugging in Visual Studio?

In the Visual Studio toolbar, make sure the configuration is set to Debug. To start debugging, select the profile name in the toolbar, such as <project profile name>, IIS Express, or <IIS profile name> in the toolbar, select Start Debugging from the Debug menu, or press F5.


1 Answers

You'll want to debug it a different way:

enter image description here

like image 149
Gromer Avatar answered Oct 11 '22 02:10

Gromer