订货编码的UI测试,结果测试管理器 [英] Ordering Coded UI tests and Results in Test Manager

查看:168
本文介绍了订货编码的UI测试,结果测试管理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列的CodedUI测试方法组成一个单一的测试用例。测试方法需要按顺序运行(IE测试方法运行然后testmethodb然后测试方法),我想让结果显示在Microsoft Test Manager中,看起来像testmethoda传递,testmethodb传递,testmethodc失败。有没有办法做到这一点,同时能够运行多个迭代的整个测试用例?

I have a series of CodedUI test methods that make up a single test case. The test methods need to run in order (IE testmethoda runs then testmethodb and then testmethodc) and I want the results to show up in Microsoft Test Manager to look like testmethoda passed, testmethodb passed, testmethodc failed. Is there a way to do this while being able to run multiple iterations of the overall test case?

我试过将测试方法放入一个测试方法,并调用那。这给了我想要的测试命令和进行多个测试运行的能力,但测试经理在整个测试用例上显示单个通过/失败。

I have tried are putting the test methods into a single test method and calling that. This gives me the desired test order and the ability to make multiple test runs, but test manager shows a single pass/fail on the entire test case.

我也试过将数据源附加到各个测试方法,并在测试管理器中对它们进行排序,这在测试管理器中给出了所需的测试结果,但是副作用是,如果我想运行多个数据行,那么命令就会混乱。例如,3个数据行将运行:

I have also tried attaching a datasource to the individual test methods and ordering them in test manager which gives me the desired test results in test manager but has the side effect that if i want to run more than one data row the order gets messed up. For example 3 data rows would run:

testmethoda

testmethoda

testmethoda

testmethoda
testmethoda
testmethoda

testmethodb

testmethodb

testmethodb

testmethodb
testmethodb
testmethodb

testmethodc

testmethodc

testmethodc

testmethodc
testmethodc
testmethodc

我想让它们运行:

testmethoda

testmethodb

testmeothdc

I want them to run:
testmethoda
testmethodb
testmeothdc

testmethoda

testmethodb

testmethodc等。

testmethoda
testmethodb
testmethodc etc..

I已经考虑过使用有序测试,但仍然显示为一个单一的测试在MTM,没有一个我知道的数据驱动它的方法,所以它会有它自己的问题。

I have thought about using an ordered test as well but that still shows up as a single test in MTM and there isn't a method I am aware of to data drive it anyways so it would have it's own problems.

我在VS或MTM中缺少一个功能来获得这些结果?也许一个方法,将允许我在结果文件中定义测试运行?编写/编辑trx文件会将我的结果写入MTM吗?我有一种感觉,我也必须更改TFS数据库,这不是一个选项。

Is there a feature that I am missing in VS or MTM to get these results? Maybe a method that would allow me to define a test run in the results file? Would writing/editing the trx file get my results into MTM? I have a feeling I would also have to make changes to the TFS database which isn't an option.

推荐答案

我不认为有办法通过VS或MTM。将所有测试方法添加到单个测试方法的选项听起来不错,但是当其中一个失败时,父测试方法停止并抛出内部测试抛出的AssertFailedException。

I don't think there is a way to do this through VS or MTM. The option to add all your test methods on a single one sounds good but when one of them fails then the 'parent' test method stops and throws the 'AssertFailedException' that one of the inner tests had thrown.

但是,如果你的测试方法(a,b,c ...)完全不受另一个的影响(这意味着如果testMethodA失败,运行没有问题),我会尝试捕获所有的内部异常,最后打印哪些方法传递而不是。

However, if your test methods (a, b, c...) are completely unaffected one by the other (this means that if the testMethodA fails the other tests can run without problems), I would try to catch all the internal exceptions and at the end print which methods passed and which not.

[TestClass]
public class TestClass
{
    Dictionary<string, string> testMethods;
    bool testResult;

    [TestInitialize]
    public void TestInitialize()
    {
        testMethods = new Dictionary<string, string>();
        testResult = true;
    }

    [TestMethod]
    public void TestMethod()
    {
        //Run TestMethodA
        try
        {
            TestMethodA();
            testMethods.Add("TestMethodA", "Passed");
        }
        catch (AssertFailedException exception) //Edit: better catch a generic Exception because CodedUI tests often fail when searcing for UI Controls 
        {
            testResult = false;
            testMethods.Add("TestMethodA", "Failed: " + exception.Message);
        }

        //Run TestMethodB
        try
        {
            TestMethodB();
            testMethods.Add("TestMethodB", "Passed");
        }
        catch (AssertFailedException exception)
        {
            testResult = false;
            testMethods.Add("TestMethodB", "Failed: " + exception.Message);
        }
    }

    [TestCleanup]
    public void TestCleanup()
    {
        foreach (KeyValuePair<string, string> testMethod in testMethods)
        {
            //Print the result for each test method
            TestContext.WriteLine(testMethod.Key.ToString() + " --> " + testMethod.Value.ToString());
        }

        //Assert if the parent test was passed or not.
        Assert.IsTrue(testResult, "One or more inner tests were failed.");
    }
}

您还可以创建一个不同的类,这种行为避免所有这些'try-catch'。

You could also create a different class that will manage all this behaviour to avoid all these 'try-catch'.

这篇关于订货编码的UI测试,结果测试管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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