数据问题驱动的测试MSTest的中 [英] Problems with data driven testing in MSTest

查看:490
本文介绍了数据问题驱动的测试MSTest的中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让驱动测试在C#与MSTest的/硒工作数据。
下面是我的一些$ C $的ç试图将其设置一个例子:

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

    ...

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

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

该错误是强调两个语句的TestContext.DataRow的一部分。
我真的一直在挣扎与这一个,谢谢!

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

推荐答案

尝试:

public TestContext TestContext { get; set; }

和尝试使用它像:

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

这篇关于数据问题驱动的测试MSTest的中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆