MSTest 中数据驱动测试的问题

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

问题描述

我正在尝试使用 MSTest/Selenium 在 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:ProjectsSeleniumProjectSeleniumProjectMaverickTest.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:ProjectsSeleniumProjectSeleniumProjectMaverickTest.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 中数据驱动测试的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)