Problems with data driven testing in MSTest

天涯浪子 提交于 2019-12-04 20:34:13

问题


I am trying to get data driven testing to work in C# with MSTest/Selenium. Here is a sample of some of my code trying to set it up:

[TestClass]
public class NewTest
{
    private ISelenium selenium;
    private StringBuilder verificationErrors;
    [DeploymentItem("GoogleTestData.xls")]
    [DataSource("System.Data.OleDb",
    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=GoogleTestData.xls;Persist Security Info=False;Extended Properties='Excel 8.0'",
    "TestSearches$", DataAccessMethod.Sequential)]

    [TestMethod]
    public void GoogleTest()
    { 
        selenium = new DefaultSelenium("localhost", 4444, "*iehta", http://www.google.com);
        selenium.Start();
        verificationErrors = new StringBuilder();
        var searchingTerm = TestContext.DataRow["SearchingString"].ToString();
        var expectedResult = TestContext.DataRow["ExpectedTextResults"].ToString();

    ...

Here's my error: Error 3 An object reference is required for the non-static field, method, or property 'Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.DataRow.get' E:\Projects\SeleniumProject\SeleniumProject\MaverickTest.cs 32 33 SeleniumProject

The error is underlining the "TestContext.DataRow" part of both statements. I've really been struggling with this one, thanks!


回答1:


try:

public TestContext TestContext { get; set; }

and try using it like:

this.TestContext.DataRow["SearchingString"].ToString();


来源:https://stackoverflow.com/questions/2993298/problems-with-data-driven-testing-in-mstest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!