一尘不染

MSTest中数据驱动测试的问题

selenium

我正在尝试通过MSTest / Selenium在C#中进行数据驱动的测试。这是我尝试设置的一些代码示例:

[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();

    ...

这是我的错误:错误3非静态字段,方法或属性’Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.DataRow.get’需要对象引用E:\
Projects \ SeleniumProject \ SeleniumProject \ MaverickTest.cs 32 33
SeleniumProject

该错误突出显示了两个语句的“ TestContext.DataRow”部分。我真的一直在努力挣扎,谢谢!


阅读 434

收藏
2020-06-26

共1个答案

一尘不染

尝试:

public TestContext TestContext { get; set; }

并尝试像这样使用它:

this.TestContext.DataRow["SearchingString"].ToString();
2020-06-26