Dot-Net

測試上下文為空

  • March 25, 2019

很簡單的測試:

[TestClass]
public class MyTestClass
{
   private TestContext _testContext;
   protected TestContext TestContext
   {
       get { return _testContext; }
       set { _testContext = value; }
   }

   [TestMethod]
   [HostType("ASP.NET")]
   [UrlToTest("http://localhost/MyPage.aspx")]
   public void TestMyPage()
   {
       Assert.IsNotNull(TestContext);
   }
}

失敗… 現在我使用的是 VS2008 開發版。有沒有可能解決這個問題?或者我需要一個測試(或團隊套件)版本?

謝謝。

PS 需要訪問 TestContext 對象才能訪問它的 RequestedPage 屬性

我很確定 TestContext 必須是公共屬性才能讓框架為您設置它。你試過公開嗎?

引用自:https://stackoverflow.com/questions/3065549