What would be an alternate to [TearDown] and [SetUp] in MSTest?

拈花ヽ惹草 提交于 2019-11-26 11:55:31

问题


When I use MSTest Framework, and copy the code that Selenium IDE generated for me, MSTest doesn\'t recognize [TearDown] and [SetUp]. What is the alternative to this?


回答1:


You would use [TestCleanup] and [TestInitialize] respectively.




回答2:


Keep in mind that your Initialize/Cleanup methods have to use the right signature.

http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.classinitializeattribute.aspx

    [AssemblyInitialize()]
    public static void AssemblyInit(TestContext context) {}

    [ClassInitialize()]
    public static void ClassInit(TestContext context) {}

    [TestInitialize()]
    public void Initialize() {}

    [TestCleanup()]
    public void Cleanup() {}

    [ClassCleanup()]
    public static void ClassCleanup() {}

    [AssemblyCleanup()]
    public static void AssemblyCleanup() {}



回答3:


[TestInitialize] and [TestCleanup] at the individual test level, [ClassInitialize] and [ClassCleanup] at the class level.




回答4:


You can use [TestInitialize] for [SetUp] and [TestCleanup] for [TearDown].



来源:https://stackoverflow.com/questions/6193744/what-would-be-an-alternate-to-teardown-and-setup-in-mstest

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