如何使用Visual Studio排序执行方法以进行集成测试? [英] How to order methods of execution using Visual Studio to do integration testing?

查看:116
本文介绍了如何使用Visual Studio排序执行方法以进行集成测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于使用VS 2010进行集成测试,我有两个问题

I have 2 questions in regard doing integration testing using VS 2010

首先,我真的很需要一种方法来按我希望的顺序执行这些测试方法.注意:我知道在单元测试中,方法应该与其他任何方法独立运行,但是这些是集成测试,我确实取决于首先运行哪种方法的顺序.

First, I'm really in need of finding a way to execute these testing methods in the order I want them to. Note: I know in Unit Testing, methods should run standalone from anything else, but these are integration tests which I do depend on the order of which method runs first.

要注意的是,有没有一种方法可以通过运行测试来保持局部变量?例如,下面的代码现在失败了.

On the same note, is there a way to keep a local variable through running the tests? For example like the following code which right now fails.

[TestClass]
public class UnitTest1
{
    int i = 0;
    [TestMethod]
    public void TestMethod1()
    {
        i = 5;
    }

    [TestMethod]
    public void TestMethod2()
    {
        Assert.AreEqual(5, i);
    }
}

那么有什么方法可以做吗?

So is there a way to do any of these?

推荐答案

要按特定顺序执行测试,我遵循以下步骤:

To execute tests in a specific order I followed the next steps:

在具有test1,test2和test3的测试项目中

In a test project with test1, test2 and test3

1右键单击项目添加"->新测试...".
2选择订购的测试"
3双击出现的文件"OrderedTest1.orderedtest"

1 Right click on the project 'Add'->'new test..."
2 Select 'Ordered Test'
3 Double click in the file that appears "OrderedTest1.orderedtest"

4如果先前未构建,则构建项目
5从可用测试列表中选择所需的测试并订购

4 Build the project if was not build previously
5 From the list of available test select the test you want and order them

从那时起,测试列表编辑器中会出现一个新测试

From that point on there appears a new test in the test list editor

这是一个额外的测试,它以正确的顺序运行附带的测试,但是如果您不小心运行项目中的所有测试,则有序列表中包含的测试将被执行两次,因此您需要以某种方式管理列表或测试类别为了避免这种情况.
我尝试禁用单个测试,但同时也禁用了有序测试,我不知道有更好的方法.

It is an extra test that runs the enclosed tests in the correct order, but if you run all the test in the project carelessly the tests included in the ordered list will be executed twice so you need to somehow manage lists or test categories to avoid that.
I tried disabling the individual tests but that also disables the ordered test, I don't know a better way to do so.

这篇关于如何使用Visual Studio排序执行方法以进行集成测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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