MyTestInitialize() and MyTestCleanup()

柔情痞子 提交于 2019-12-11 12:32:08

问题


  [TestInitialize()]
    public void MyTestInitialize()
    {

        Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.Disabled;
        Playback.PlaybackSettings.ShouldSearchFailFast = false;
        Playback.PlaybackSettings.DelayBetweenActions = 300;
        Playback.PlaybackSettings.SearchTimeout = 30000;            
        Playback.PlaybackSettings.SearchInMinimizedWindows = false;            
    }


 [TestCleanup()]
    public void MyTestCleanup()
    {         
        Logger.CreateResultFile(ResultsLog, TestCaseInfo);
    }

Is there a way that everytime i create a new codedUI test, the MyTestInitialize() and MyTestCleanup() should be created with above lines in it instead of blank ones?


回答1:


Creating a base class and let all your other test classes inherit from it. like this:

 [CodedUITest]
public class BaseTestClass
{
    [TestInitialize()]
    public void MyTestInitialize()
    {

        Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.Disabled;
        Playback.PlaybackSettings.ShouldSearchFailFast = false;
        Playback.PlaybackSettings.DelayBetweenActions = 300;
        Playback.PlaybackSettings.SearchTimeout = 30000;
        Playback.PlaybackSettings.SearchInMinimizedWindows = false;
    }

    [TestCleanup()]
    public void MyTestCleanup()
    {
        Console.Write("Do CleanUp");

    }
}

 [CodedUITest]
public class derivedTestClass : BaseTestClass
{
    [TestMethod]
    public void Tests()
    {

        Console.Write("Test");
    }

}

when you'll invoke Tests() the init and cleanup methods will be called



来源:https://stackoverflow.com/questions/31134254/mytestinitialize-and-mytestcleanup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!