在测试管理器中订购编码的UI测试和结果
本文关键字:测试 UI 结果 编码 管理器 | 更新日期: 2023-09-27 18:20:54
我有一系列CodedUI测试方法,它们组成了一个测试用例。测试方法需要按顺序运行(IE testmethoda运行,然后testmethodb,然后testmethodc),我希望结果显示在Microsoft测试管理器中,看起来像testmethoda通过,testmethodb通过,testmethodc失败。有没有一种方法可以做到这一点,同时能够运行整个测试用例的多次迭代?
我尝试过将测试方法放入一个测试方法中并调用它。这为我提供了所需的测试顺序和进行多次测试运行的能力,但测试管理器在整个测试用例中显示了一次通过/失败。
我还尝试将数据源附加到各个测试方法,并在测试管理器中对它们进行排序,这在测试管理中为我提供了所需的测试结果,但副作用是,如果我想运行多个数据行,则顺序会变得混乱。例如,将运行3个数据行:
测试方法a
测试方法a
测试方法
测试方法b
测试方法b
测试方法b
测试方法
测试方法
测试方法
我希望他们运行:
测试方法a
测试方法b
测试直流
测试方法a
测试方法b
测试方法等。
我也想过使用有序测试,但这在MTM中仍然是一个单一的测试,而且我不知道有一种方法可以数据驱动它,所以它会有自己的问题。
我在VS或MTM中是否缺少一个功能来获得这些结果?也许是一个允许我在结果文件中定义测试运行的方法?编写/编辑trx文件会让我的结果进入MTM吗?我有一种感觉,我还必须对TFS数据库进行更改,这不是一种选择。
我认为没有办法通过VS或MTM来实现这一点。将所有测试方法添加到一个方法上的选项听起来不错,但当其中一个方法失败时,"父"测试方法会停止并抛出其中一个内部测试抛出的"AssertFailedException"。
然而,如果您的测试方法(a、b、c…)完全不受另一个的影响(这意味着如果testMethodA失败,其他测试可以毫无问题地运行),我会尝试捕捉所有内部异常,并在最后打印哪些方法通过了,哪些方法没有通过。
[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.");
}
}
您还可以创建一个不同的类来管理所有这些行为,以避免所有这些"尝试捕获"。