单元测试在Visual Studio中控制执行顺序 [英] Controlling execution order of unit tests in Visual Studio

查看:1300
本文介绍了单元测试在Visual Studio中控制执行顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我做了搜索这个良好的信息。
我有一系列的调用,一旦初始化静态类单元测试,集不能(或者我不希望)更改属性。

Okay, I'm done searching for good information on this. I have a series of Unit Tests that call a static class which, once initialized, sets properties that cannot (or I don't wish to) change.

我的问题是我不能强制执行一组为了使测试运行。如果我可以,我可以以这样的方式运行它们的静态属性会以可靠的方式进行设置,我可以断言他,但不幸的是,Microsoft.VisualStudio.TestTools.UnitTesting框架只是运行在他们看似随机的顺序

My problem is I cannot enforce a set order for the tests to run. If I could, I could run them in such a way as the static properties would be set in a reliable way, and I could Assert on them, but unfortunately the Microsoft.VisualStudio.TestTools.UnitTesting framework just runs them in a seemingly random order.

所以,我发现这个的 http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.priorityattribute.aspx 其说,在备注一节这个属性是不使用测试系统,它被提供给用户的定制的目的。咦?有什么好处呢呢?难道他们以为我会写我自己的测试包装借此神话般特性的优势(其中我可以很容易地写自己,如果我想去的努力,水平...)

So, I found this http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.priorityattribute.aspx which says in the Remarks section "This attribute is not used by the test system. It is provided to the user for custom purposes." Huh? What good is it then? Do they expect me to write my own testing wrapper to take advantage of this fabulous attribute (of which I could easily write myself if I wanted to go to that level of effort...)

所以,够了咆哮;底线,是有办法控制我的单元测试运行的顺序?

So, enough of the rant; Bottom line, is there a way to control the order my unit tests run?

[TestMethod]
[Priority(0)]

等。似乎没有工作,这是有道理的,因为微软表示,它不会。

etc. does NOT seem to work, which makes sense, since Microsoft says it won't.

另外,请关于违反隔离没有意见。该分离的TestClass什么,我的测试,而不是个人TestMethods。无论如何,每个测试可以独立运行得很好,他们只是不能一起在一个随机的顺序没有办法推倒静态类运行。

Also, please no comments about "violating isolation". The TestClass isolates what I am testing, not the individual TestMethods. Regardless, each test can be run independently just fine, they just can't be run together in a random order as there is no way to tear down the static class.

唉,我也知道顺序测试。

Oh, I also know about "Ordered Test".

推荐答案

合并你的测试成一个巨大的考验会工作。为了使试验方法更具可读性,你可以做这样的事情。

Merge your tests into one giant test will work. To make the test method more readable, you can do something like

[TestMethod]
public void MyIntegratonTestLikeUnitTest()
{
    AssertScenarioA();

    AssertScenarioB();

    ....
}

private void AssertScenarioA()
{
     // Assert
}

private void AssertScenarioB()
{
     // Assert
}

其实你有问题,建议你应该提高执行的可测试性。

Actually the issue you have suggests you probably should improve the testability of the implementation.

这篇关于单元测试在Visual Studio中控制执行顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆