本文介绍了MyTestInitialize()和MyTestCleanup()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
[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);
}
是否有一种方法,每次我创建新的codedUI测试时,MyTestInitialize( )和MyTestCleanup()应该在上面的行而不是空白行中创建吗?
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?
推荐答案
创建基类并让所有您的其他测试类将从其继承。像这样:
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");
}
}
当您调用Tests时( )的初始化和清除方法将被称为
when you'll invoke Tests() the init and cleanup methods will be called
这篇关于MyTestInitialize()和MyTestCleanup()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!