1
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;

    }
}

It gives an error when I use it in codeduitest (testmethod) System.NullReferenceException : Object reference not set to an instance of an object. What is the problem? What can I do?Thanks...

    [TestMethod]
    public void Test1()
    {          
        portalmtm();
        this.UIMap....
        this.UIMap....
    }
  public TestContext TestContext
    {
        get
        {
            return testContextInstance;
        }
        set
        {
            testContextInstance = value;
        }
    }
    private TestContext testContextInstance;
Erdem Azaklı
  • 255
  • 1
  • 8
  • 27

2 Answers2

1

The class has to be decorated with the CodedUITestAttribute attribute.

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
0

Put [TestMethod] above the method like this and it should work. (TestMethod) means nothing, you must use the square brackets.

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

By the way if your going to put any automated test methods in this I'm pretty sure it cannot be static.

matthiasgh
  • 321
  • 1
  • 11