至于TestLibrary的初始化,完全可以放到每一个测试类型的TestInitializer里面,如下表所示:
[TestClass] public class AddBlogTest { private TestContext testContextInstance; public TestContext TestContext { get { return testContextInstance; } set { testContextInstance = value; } } private TestLibrary TestLibrary; private ISelenium selenium; [TestInitialize] public void SetupTest() { TestLibrary = TestLibrary.SetupTest(TestContext); selenium = TestLibrary.Selenium; } [TestCleanup] public void TeardownTest() { TestLibrary.Shutdown(); } } |
乍看起来,把LogOn测试用例分解成那么多的类型,有点画蛇添足,实际上这些函数库正是为了更方便地创建后续的测试用例耗费的磨刀的功夫。例如下面的代码是基于一些创建好了的函数编写的测试用例:
[TestMethod] public void CreateBlog() { TestLibrary.UserHelper.LogOnAsAdmin(); var blog = TestLibrary.BlogHelper.CreateBlog("博客的标题", "博客的链接"); selenium.Click("link=管理博客"); selenium.WaitForPageToLoad(Consts.TimeToWaitForPageLoad); Assert.IsTrue(selenium.IsElementPresent(string.Format("link={0}", blog.Title))); } |
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/