我找不到类似的帖子,所以我希望这不是重复的。
我有 ac# 类库,我正在尝试在 Visual Studio 2012 中运行单元测试。我在我的解决方案中添加了一个新的单元测试项目,并在那里添加了我的主项目作为参考。我已将我的单元测试项目设置为启动项目。当我尝试调试时,我收到一条错误消息
不能直接启动具有类库输出类型的项目。
为了调试这个项目,将一个可执行项目添加到这个引用库项目的解决方案中。将可执行项目设置为启动项目。
根据msdn的演练,当我点击调试时,它应该正在运行测试。有什么想法吗?这是我的单元测试代码:
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
//}
}
}