Код: Выделить всё
[TestClass]
public class UnitTest1:BaseDriver
{
ExcelTest sd;
private TestContext instance;
public TestContext TestContext
{
set { instance = value; }
get { return instance; }
}
public UnitTest1()
{
sd = new ExcelTest(_driver);
}
[TestInitialize]
public void Testinitialize()
{
}
[TestMethod]
[DeploymentItem("TestData.csv")]
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", @"C:\Users\nidumukv\Documents\Visual Studio 2012\Projects\BMICalculator\BMICalculator\DataFiles\TestData.csv", "TestData#csv", DataAccessMethod.Sequential)]
public void DDtest_usingCSV()
{
string feet = TestContext.DataRow["feet"].ToString();
string inches = TestContext.DataRow["inches"].ToString();
string weight = TestContext.DataRow["weight in pounds"].ToString();
string BMI = TestContext.DataRow["BMI"].ToString();
sd.TestUsingCSV(feet,inches,weight,BMI);
}
[TestCleanup]
public void cleanup()
{ _driver.Quit(); }
}
Я пытаюсь определить переменные, которые находятся в методе «DDtest_usingCSV», в отдельном классе, чтобы тест не становится корявым. Но всякий раз, когда я определяю другой тестовый контекст в другом классе, я получаю исключение NullReferenceException. Я пробовал передавать свойство между классами. Но я не смог этого сделать (еще учусь).
Ниже приведен класс, который я пытаюсь инициализировать TestContext
Код: Выделить всё
public class ExcelTest:PageElements
{
public IWebDriver _driver;
public ExcelTest(IWebDriver driver):base(driver)
{
_driver = driver;
}
public void TestUsingCSV(string _feet,string _inches,string _weight,string _BMI)
{
feet.SendKeys(_feet);
inches.SendKeys(_inches);
weight.SendKeys(_weight);
compute_btn.Click();
}
}
И при объявлении свойства TestContext, как указано ниже, почему мы используем «TestContext» в качестве имени свойства вместо экземпляра??
Код: Выделить всё
private TestContext instance;
public TestContext TestContext
{
set { instance = value; }
get { return instance; }
}
Код: Выделить всё
public void DDtest_usingCSV()
{
string feet = TestContext.DataRow["feet"].ToString();
string inches = TestContext.DataRow["inches"].ToString();
string weight = TestContext.DataRow["weight in pounds"].ToString();
string BMI = TestContext.DataRow["BMI"].ToString();
sd.TestUsingCSV(feet,inches,weight,BMI);
}
Подробнее здесь: https://stackoverflow.com/questions/367 ... ther-class