我有一个基类ScriptBase
,它有一个名为MyTestInitialize()
. 当我MyTestInitialize()
从派生类调用时,testContextInstance
值为null
。有什么解决办法吗?请帮忙,因为我是自动化测试的新手。提前致谢
[CodedUITest]
public class ScriptsBase
{
public ScriptsBase()
{
}
private static TestContext bingTestContext;
public static TestContext BingTestContext
{
get { return ScriptsBase.bingTestContext; }
set { ScriptsBase.bingTestContext = value;}
}
#region TestInitialize
//Use TestInitialize to run code before running each test
[TestInitialize()]
public virtual void MyTestInitialize()
{
Browser.CloseAllBrowsers();
BingTestContext = testContextInstance;
}
#endregion
#region TestCleanup
//Use TestCleanup to run code after each test has run
[TestCleanup()]
public virtual void MyTestCleanup()
{
PPI.HomePage = new HomePageUI();
Browser.CloseAllBrowsers();
}
#endregion
#region TestContext
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
private TestContext testContextInstance;
#endregion
}
public class DestinationMasterTestScripts : ScriptsBase
{
public DestinationMasterTestScripts()
{
}
[TestInitialize()]
public override void MyTestInitialize()
{
Console.WriteLine("Initialize");
base.MyTestInitialize();
}
}