2
你好,我嘗試添加單元測試,但看起來像它的困難,我沒有想到:(是否有任何人誰可以幫我解釋一下如何使一個?單元測試C#創建第一個測試
public class USerService : IUSerService
{
[DataMember]
public int ID { get; set; }
[DataMember]
public string Login { get; set; }
[DataMember]
public string UserType { get; set; }
public List<UserInfo> GetUserU()
{
QuizDBEntities contex = new QuizDBEntities();
var userU = from a in contex.UserInfoes select a;
return userU.ToList();
}
}
我做創建使用「創建單元測試」,但在這裏它變成對我來說很難,即時通訊丟失,它不是那麼容易像谷歌的教程。
[TestClass()]
public class USerServiceTest
{
private TestContext testContextInstance;
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
#region Additional test attributes
//
//You can use the following additional attributes as you write your tests:
//
//Use ClassInitialize to run code before running the first test in the class
//[ClassInitialize()]
//public static void MyClassInitialize(TestContext testContext)
//{
//}
//
//Use ClassCleanup to run code after all tests in a class have run
//[ClassCleanup()]
//public static void MyClassCleanup()
//{
//}
//
//Use TestInitialize to run code before running each test
//[TestInitialize()]
//public void MyTestInitialize()
//{
//}
//
//Use TestCleanup to run code after each test has run
//[TestCleanup()]
//public void MyTestCleanup()
//{
//}
//
#endregion
/// <summary>
///A test for USerService Constructor
///</summary>
// TODO: Ensure that the UrlToTest attribute specifies a URL to an ASP.NET page (for example,
// http://.../Default.aspx). This is necessary for the unit test to be executed on the web server,
// whether you are testing a page, web service, or a WCF service.
[TestMethod()]
[HostType("ASP.NET")]
[AspNetDevelopmentServerHost("C:\\Users\\Drage\\Desktop\\lekcja1\\Dunskiseba", "/Dunskiseba")]
[UrlToTest("http://localhost/Dunskiseba")]
public void USerServiceConstructorTest()
{
USerService_Accessor target = new USerService_Accessor();
Assert.Inconclusive("TODO: Implement code to verify target");
}
更具體。什麼不適合你。當您構建「Solution」/「Project」時,您的TestMethod應顯示在「文本瀏覽器」視圖中。 –