Exemple #1
0
        /// <summary>
        /// get a test case id. If the test case does not exist then create one
        /// </summary>
        /// <param name="testName"></param>
        /// <returns>a valid test case id or 0 in case of failure</returns>
        public int GetTestCaseId(string testName)
        {
            int TCaseId = getTestCaseByName(testName, testSuiteId);

            if (TCaseId == 0)
            {
                // need to create test case
                GeneralResult result = proxy.CreateTestCase(connectionData.UserId, testSuiteId, testName, testProjectId,
                                                            "Automated TestCase", new TestStep[0], "", 0,
                                                            true, ActionOnDuplicatedName.Block, 2, 2);
                TCaseId = result.additionalInfo.id;
                int tcExternalId = result.additionalInfo.external_id;
                if (result.status == false)
                {
                    Console.Error.WriteLine("Failed to create TestCase for {0}", testName);
                    Console.Error.WriteLine(" Reason {0}", result.message);
                    return(0);
                }
                string externalId = string.Format("{0}-{1}", currentProject.prefix, tcExternalId);
                int    featureId  = proxy.addTestCaseToTestPlan(currentProject.id, testPlanId, externalId, result.additionalInfo.version_number);
                if (featureId == 0)
                {
                    Console.Error.WriteLine("Failed to assign TestCase {0} to testplan", testName);
                    return(0);
                }
            }
            return(TCaseId);
        }
        public void CreateTestCase()
        {
            var project    = testlink.GetProject("CMGE");
            var testSuites = testlink.GetFirstLevelTestSuitesForTestProject(project.id);

            testSuites.ForEach(a => Console.WriteLine($"Test Suites: {a.id}, {a.name}"));

            var testSuite = testSuites.First();
            var created   = testlink.CreateTestCase("user", testSuite.id, "新创建的测试用例", project.id, "summary",
                                                    new[] { new TestStep(1, "<p>click(<img alt=\"\" src=\"http://dev-wiki-1.cmit.local/resources/assets/cmgos.png \" style=\"height:71px; width:139px\" />)</p>", "find", true, 2) },
                                                    "", 1, false, ActionOnDuplicatedName.CreateNewVersion, 0, 0);

            Console.WriteLine($"{created.id}, {created.additionalInfo.has_duplicate}, {created.status}, {created.message}, {created.operation}");
            var testCases = testlink.GetTestCaseIDByName("新创建的测试用例");

            Assert.NotEmpty(testCases);
        }