Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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
        //}
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
329 views
Welcome To Ask or Share your Answers For Others

1 Answer

You'll want to debug it a different way:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...