MSTESTでのデータ駆動型テストの問題
-
24-10-2019 - |
質問
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: seleniumproject seleniumproject mavericktest.cs 3222 33 seleniumproject
エラーは、両方のステートメントの「testContext.Datarow」部分を強調しています。私は本当にこれに苦労してきました、ありがとう!
解決
試す:
public TestContext TestContext { get; set; }
次のように使用してみてください。
this.TestContext.DataRow["SearchingString"].ToString();
所属していません StackOverflow