![](/img/trans.png)
[英]Can I link C# coded UI tests into test manager without an associated manual test?
[英]Ordering Coded UI tests and Results in Test Manager
我有一系列的CodedUI測試方法,這些方法組成了一個測試用例。 測試方法需要按順序運行(即先運行IE testmethoda,然后運行testmethodb,然后運行testmethodc),並且我希望結果顯示在Microsoft Test Manager中,看起來像通過了testmethoda,通過了testmethodb,通過了testmethodc。 有一種方法可以同時運行整個測試用例的多次迭代嗎?
我嘗試過將測試方法放入單個測試方法中並進行調用。 這給了我所需的測試順序,並且可以進行多個測試,但是測試管理器在整個測試用例中僅顯示一次通過/失敗。
我還嘗試將數據源附加到各個測試方法,並在測試管理器中對它們進行排序,這給了我在測試管理器中所需的測試結果,但是卻產生了副作用,即如果我要運行多個數據行,則該命令會變得混亂。 例如,將運行3個數據行:
測試方法
測試方法
測試方法
測試方法
測試方法
測試方法
測試方法
測試方法
測試方法
我要他們跑步:
測試方法
測試方法
測試方法
測試方法
測試方法
testmethodc等。
我也曾考慮過使用有序測試,但仍然會在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.");
}
}
您也可以創建一個不同的類來管理所有這些行為,以避免所有這些“ try-catch”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.