2013-09-23 69 views

回答

2

您可以在Conection上創建過濾器。下面的示例按名稱搜索測試,但如果您要在「TS_TEST_ID」上更改「TS_TEST_NAME」,則可以使用測試ID進行搜索。

public int findTestCase(TDAPIOLELib.TDConnection connection, string testCaseName) 
     { 
      TestFactory tstF = connection.TestFactory as TestFactory; 
      TDFilter testCaseFilter = tstF.Filter as TDFilter; 
      testCaseFilter["TS_TEST_NAME"] = testCaseName; 
      List testsList = tstF.NewList(testCaseFilter.Text); 
      if(testsList != null && testsList.Count == 1) 
      { 
       log.log("Test case " +testCaseName+ " was found "); 
       Test tmp = testsList[0] as Test; 
       return (int)tmp.ID; 
      } 

     return -1; 
    } 
+0

感謝您的答覆.... – yogikam78

5

假設你有一個開放的連接,並知道使用該ID的測試存在(例如,從以前的查詢結果),你可以做到以下幾點:

int testId = 1234; 
TestFactory tf = connection.TestFactory; 
Test t = tf[id]; 

到TestFactory中索引的通話將用「Item不存在」引發COMException。如果使用該ID的測試不存在。

如果您不知道是否與該ID的測試存在,則可以執行以下操作:

int testId = 1234; 
TestFactory tf = connection.TestFactory; 
TDFilter filter = tf.Filter; 
filter["TS_TEST_ID"] = id.ToString(); 
List tests = tf.NewList(filter.Text); // List collection is the ALM List, not .NET BCL List. 
Test t = (tests.Count > 0) ? tests[1] : null; // ALM List collection indexes are 1-based, and test ID is guaranteed to be unique and only return 1 result if it exists. 
+0

感謝您的答覆.... – yogikam78

相關問題