public static SortedDictionary <string, string> GetAllTestCases(string suites, string planId)
        {
            SortedDictionary <string, string> lsTestCasesQuery = new SortedDictionary <string, string>();

            try
            {
                ITestSuiteHelper iTSuiteHelp = proj.TestSuites;
                string[]         suiteArray  = suites.Split(',');
                foreach (string str in suiteArray)
                {
                    ITestSuiteBase      iTSB    = iTSuiteHelp.Find(Convert.ToInt32(str));
                    ITestCaseCollection itCColl = iTSB.AllTestCases;

                    foreach (ITestCase iTc in itCColl)
                    {
                        lsTestCasesQuery.Add(iTc.Id.ToString(), iTc.Title.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                lsTestCasesQuery.Add("-1", "Error. Load Project,pland and config");
            }
            return(lsTestCasesQuery);
        }
        void Access_Excel(ITestCaseCollection testcases)
        {
            try
            {

                FileInfo new_file = new FileInfo(File_Name.Text);

               // FileInfo template = new FileInfo(System.Windows.Forms.Application.StartupPath + "\\Resources\\Test_Case_Template.xlsx");
                FileInfo template = new FileInfo(Directory.GetCurrentDirectory() + "\\Test_Case_Template.xlsx");
                using (ExcelPackage xlpackage = new ExcelPackage(new_file,template))
                {
                    ExcelWorksheet worksheet = xlpackage.Workbook.Worksheets["Test Case"];

                    GetTestCases(testcases, worksheet);
                    xlpackage.Save();

                    MessageBox.Show("File has been saved at " + File_Name.Text);
            }

            }
            catch (Exception theException)
            {
                String errorMessage;
                errorMessage = "Error: ";
                errorMessage = String.Concat(errorMessage, theException.Message);
                errorMessage = String.Concat(errorMessage, " Line: ");
                errorMessage = String.Concat(errorMessage, theException.Source);

                MessageBox.Show(errorMessage, "Error");

            }
        }
示例#3
0
        /// <summary>
        /// Проходит по всем тестовым ситуациям тестового плана и заполняет Excel таблицу,
        /// указывая подзаголовком категорию теста - наименования тестовой ситуации.
        /// </summary>
        private void ByTestSuites()
        {
            try
            {
                this.plans = teamProject.TestPlans.Query("Select * From TestPlan");
                foreach (ITestPlan plan in plans)
                {
                    if (plan.Name == testPlanName)
                    {
                        this.testSuites = plan.RootSuite.Entries;
                    }
                }
                foreach (ITestSuiteEntry suite_entry in testSuites)
                {
                    this.suite = suite_entry;
                    IStaticTestSuite newSuite = suite_entry.TestSuite as IStaticTestSuite;
                    if (newSuite != null)
                    {
                        xlWorkSheet.get_Range("a" + row, "d" + row).Merge(true);
                        xlWorkSheet.Cells[row, 1]                     = newSuite.Title;
                        xlWorkSheet.Cells[row, 1].Font.Bold           = true;
                        xlWorkSheet.Cells[row, 1].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;

                        row = row + 1;
                        ITestCaseCollection cases = newSuite.AllTestCases;
                        ByTestCases(cases);
                    }
                    else
                    {
                        ITestCase test = suite_entry.TestCase as ITestCase;
                        if (test != null)
                        {
                            ByTest(test);
                        }
                    }
                }
            }
            catch { }
        }
        static void Main(string[] args)
        {
            var u = new Uri("http://server:8080/tfs/DefaultCollection");
            var c = new VssClientCredentials();
            TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(u, c);

            tpc.EnsureAuthenticated();
            ITestManagementService     itms  = tpc.GetService <ITestManagementService>();
            ITestManagementTeamProject ittp  = itms.GetTeamProject("LCScrum");
            ITestSuiteBase             suite = ittp.TestSuites.Find(352);
            ITestCaseCollection        testCaseCollection = suite.AllTestCases;

            foreach (var tc in testCaseCollection)
            {
                ITestCase testcase = ittp.TestCases.Find(tc.Id);

                foreach (ITestAction action in testcase.Actions)
                {
                    Console.WriteLine(String.Format("{0} - {1}", testcase.Id, action));
                }
            }
            Console.Read();
        }
        void GetTestCases(ITestCaseCollection testcases, ExcelWorksheet oSheet)
        {
            int i = 2;

            foreach (ITestCase Testcase in testcases)
            {
                int j = 1;
                string str1 = null;
                string str2 = null;
                foreach (ITestAction action in Testcase.Actions)
                {
                    ISharedStep shared_step = null;
                    ISharedStepReference shared_ref = action as ISharedStepReference;
                    if (shared_ref != null)
                    {
                        shared_step = shared_ref.FindSharedStep();
                        foreach (ITestAction shr_action in shared_step.Actions)
                        {
                            var test_step = shr_action as ITestStep;
                            str1 = str1 + j.ToString() + "." + ((test_step.Title.ToString().Length ==0)? "<<Not Recorded>>" : test_step.Title.ToString()) + System.Environment.NewLine;
                            str2 = str2 + j.ToString() + "." + ((test_step.ExpectedResult.ToString().Length ==0) ? "<<Not Recorded>>" : test_step.ExpectedResult.ToString()) + System.Environment.NewLine;
                            j++;
                        }

                    }
                    else
                    {
                        var test_step = action as ITestStep;
                        str1 = str1 + j.ToString() + "." + ((test_step.Title.ToString().Length ==0) ? "<<Not Recorded>>" : test_step.Title.ToString()) + System.Environment.NewLine;
                        str2 = str2 + j.ToString() + "." + ((test_step.ExpectedResult.ToString().Length ==0) ? "<<Not Recorded>>" : test_step.ExpectedResult.ToString()) + System.Environment.NewLine;
                        j++;
                    }
                }

                string result = null;
                string tot_result = null;
                foreach (ITestPoint test_point in TP.QueryTestPoints(string.Format("Select * from TestPoint where TestCaseId = {0} ", Testcase.Id)))
                {
                    ITestCaseResult tc_res = test_point.MostRecentResult;
                    if (tc_res != null)
                    {
                        if (tc_res.Outcome.ToString().Equals("None"))
                           result= tc_res.TestConfigurationName +  " : In Progress" + System.Environment.NewLine;
                        else
                            result = tc_res.TestConfigurationName + " : " + tc_res.Outcome.ToString() + System.Environment.NewLine;
                    }
                    else
                        result = test_point.ConfigurationName + " : Active" + System.Environment.NewLine;

                    tot_result = tot_result + result;
                }

               Query query = new Query(_store,string.Format("SELECT [Target].[System.Id] FROM WorkItemLinks WHERE ([Source].[System.Id] = {0}) and ([Source].[System.WorkItemType] = 'Test Case')  And ([Target].[System.WorkItemType] = 'Bug')mode(MustContain)", Testcase.Id));

                WorkItemLinkInfo[] workItemLinkInfoArray = null;
                if (query.IsLinkQuery)
               {

                   workItemLinkInfoArray = query.RunLinkQuery();

               }

               else
               {

                   throw new Exception("Run link query fail. Query passed is not a link query");

               }
                string bug_list = null;
                for (int k = 0; k < workItemLinkInfoArray.Length; k++)
                {
                    if (workItemLinkInfoArray[k].LinkTypeId != 0)
                        bug_list = bug_list + workItemLinkInfoArray[k].TargetId.ToString() + System.Environment.NewLine;
                }

                oSheet.Cells[i, 1].Value = Testcase.Id.ToString();
                oSheet.Cells[i, 2].Value = Testcase.Title.ToString();
                oSheet.Cells[i, 3].Value = str1;
                oSheet.Cells[i, 4].Value = str2;
                oSheet.Cells[i, 8].Value = Testcase.WorkItem.CreatedBy.ToString();
                oSheet.Cells[i, 5].Value = Testcase.Description.ToString() + " ";
                oSheet.Cells[i, 9].Value = tot_result;
                oSheet.Cells[i, 10].Value = bug_list;

                i++;
            }
        }
示例#6
0
 private void Get_TestCases(IStaticTestSuite testSuite)
 {
     this.testCases = testSuite.AllTestCases;
 }
示例#7
0
        public void CloneTestCases(ITestSuiteBase suite, ITestSuiteBase destinationSuite)
        {
            ITestCaseCollection testCases = suite.AllTestCases;

            AddTestCasesToSuite(testCases, destinationSuite);
        }