2013-04-12 108 views
0
public class portal 
{ 
    public portal() 
    { 
    } 
    [DataSource ("Microsoft.VisualStudio.TestTools.DataSource.TestCase", "http://alm:8080/tfs/....", "15729", DataAccessMethod.Sequential), TestMethod] 

    public static void portalmtm() 
    { 
     BrowserWindow b = BrowserWindow.Launch(new System.Uri(TestContext.DataRow["portals"].ToString())); 
    } 

    public static TestContext TestContext 
    { 
     get 
     { 
      return testContextInstance; 
     } 
     set 
     { 
      testContextInstance = value; 
     } 
    } 
    private static TestContext testContextInstance; 

    } 
} 

它给当我使用它在codeduitest错误(TestMethod的) System.NullReferenceException:对象不设置到对象的实例。问题是什么?我该怎么办?谢谢...编码的UI测试System.NullReferenceException

[TestMethod] 
    public void Test1() 
    {   
     portalmtm(); 
     this.UIMap.... 
     this.UIMap.... 
    } 
    public TestContext TestContext 
    { 
     get 
     { 
      return testContextInstance; 
     } 
     set 
     { 
      testContextInstance = value; 
     } 
    } 
    private TestContext testContextInstance; 
+0

您可以检查http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net –

+2

TestContext永远不会被初始化。 –

+0

我编辑了代码.. –

回答

1

该班必须装饰CodedUITestAttribute属性。

0

把[TestMethod]放在这样的方法之上,它应该工作。 (TestMethod)意味着什么,你必须使用方括号。

 [TestMethod] 
    public static void portalmtm() 
    { 
     //Code goes here. 
    } 

顺便说一句,如果你打算把这个任何自动化测试方法我敢肯定它不能是静态的。