Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
342 views
in Technique[技术] by (71.8m points)

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

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

1 Reply

0 votes
by (71.8m points)

You'll want to debug it a different way:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...