在Visual Studio 2012不能调试一个单元测试项目 [英] Cannot debug a unit testing project in Visual Studio 2012

查看:247
本文介绍了在Visual Studio 2012不能调试一个单元测试项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到一个类似的帖子,所以我希望这不是一个重复。



我有一个C#类库,我想对在Visual Studio 2012年我添加了一个新的单元测试项目,以我的解决方案运行单元测试,加入我的主要项目中,因为一个参考。我已经把我的单元测试项目为启动项目。当我尝试调试,我得到一个错误信息




有一个类库输出类型的项目不能直接启动。



为了调试这个项目中,添加一个可执行的项目,这个解决方案,它引用库项目。将可执行项目为启动项目。






据当时 MSDN 演练,应该运行测试时,我打的调试。有什么想法吗?这里是我的单元测试代码:

 使用系统; 
使用System.Collections.Generic;
使用System.Linq的;
使用System.Text;

使用Microsoft.VisualStudio.TestTools.UnitTesting;
使用常见;使用消息
;

命名空间MessageUnitTests
{
[TestClass中]
类RegistrationTester
{
[TestMethod的]
公共无效RegistrationRequest_TestConstructorsAndFactories()
{
RegistrationRequest RR1 =新RegistrationRequest(myhandle);
Assert.AreEqual(myhandle,rr1.Handle);

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

RR1 =新RegistrationRequest();
Assert.AreEqual(,rr1.Handle);

RR1 =新RegistrationRequest(NULL);
Assert.AreEqual(NULL,rr1.Handle);

RR1 =新RegistrationRequest(myhandle);
ByteList字节=新ByteList();
rr1.Encode(字节);

RegistrationRequest RR2 = RegistrationRequest.Create(字节);
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的]
//公共无效RegistrationRequest_EncodingDecoding()
// {
//消息M1 =新RegistrationRequest(myhandle );
// m1.MessageNr = MessageNumber.Create(10,14);
// m1.ConversationId = MessageNumber.Create(10,12);
// ByteList字节=新ByteList
//}
}
}


解决方案

您会想调试它以不同的方式:




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.

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
        //}
    }
}

解决方案

You'll want to debug it a different way:

这篇关于在Visual Studio 2012不能调试一个单元测试项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆