Esempio n. 1
0
        /// <summary>
        /// deals with the results of tests
        /// </summary>
        private void HandleTest(TestMethod tm)
        {
            TestResult       tr   = tm.Run(new NullListener(), TestFilter.Empty);
            ResultSummarizer summ = new ResultSummarizer(tr);

            if (tr.IsError)
            {
                Handler.OnError(tm, tr);
            }
            else if (tr.IsFailure)
            {
                Handler.OnFailure(tm, tr);
            }
            else if (tr.IsSuccess)
            {
                Handler.OnSuccess(tm, tr);
            }
        }
Esempio n. 2
0
        public void Run()
        {
            OnTestStarted(EventArgs.Empty);

            Debug.WriteLine(string.Format("Running test {0}", _test.TestName));
            try
            {
                TestName   testName = _test.TestName;
                TestFilter filter   = new NameFilter(testName);
                TestResult result   = _test.Run(_listener, filter);
                var        summ     = new ResultSummarizer(result);
                Assert.AreEqual(1, summ.ResultCount);
            }
            catch (Exception e)
            {
                DynamoLogger.Instance.Log(e.Message);
                DynamoLogger.Instance.Log(string.Format("Failed to run test : {0}", _test.TestName));
            }

            OnTestCompleted(EventArgs.Empty);
        }
Esempio n. 3
0
        /// <summary>
        /// deals with the results of tests
        /// </summary>
        private void HandleTest(TestFixture tf, TestMethod tm, TestEnvironment te, TestSite ts)
        {
            TestResult       tr   = tm.Run(new NullListener(), TestFilter.Empty);
            ResultSummarizer summ = new ResultSummarizer(tr);

            Type           t          = tf.FixtureType;
            HttpStatusCode status     = ((Test)tm).GetProperty <HttpStatusCode>(BaseWebTest.ResponseStatusCodeKey);
            string         requestURL = ((Test)tm).GetProperty <string>(BaseWebTest.RequestURLKey);

            if (tr.IsError)
            {
                Handler.OnError(tm, te, ts, tr, requestURL, status);
            }
            else if (tr.IsFailure)
            {
                Handler.OnFailure(tm, te, ts, tr, requestURL, status);
            }
            else if (tr.IsSuccess)
            {
                Handler.OnSuccess(tm, te, ts, tr, requestURL, status);
            }
        }
Esempio n. 4
0
        private testcaseType RunTest(TestMethod t, MethodInfo[] setupMethods = null)
        {
            TestFilter filter = new NameFilter(t.TestName);

            var result = t.Run(new TestListener(), filter);

            //result types
            //Ignored, Failure, NotRunnable, Error, Success
            var testCase = new testcaseType
            {
                name     = t.TestName.Name,
                executed = result.Executed.ToString(),
                success  = result.IsSuccess.ToString(),
                asserts  = result.AssertCount.ToString(CultureInfo.InvariantCulture),
                time     = result.Time.ToString(CultureInfo.InvariantCulture)
            };

            switch (result.ResultState)
            {
            case ResultState.Cancelled:
                testCase.result = "Cancelled";
                break;

            case ResultState.Error:
                var f = new failureType {
                    message = result.Message, stacktrace = result.StackTrace
                };
                testCase.Item   = f;
                testCase.result = "Error";
                break;

            case ResultState.Failure:
                var fail = new failureType {
                    message = result.Message, stacktrace = result.StackTrace
                };
                testCase.Item   = fail;
                testCase.result = "Failure";
                break;

            case ResultState.Ignored:
                testCase.result = "Ignored";
                break;

            case ResultState.Inconclusive:
                testCase.result = "Inconclusive";
                break;

            case ResultState.NotRunnable:
                testCase.result = "NotRunnable";
                break;

            case ResultState.Skipped:
                testCase.result = "Skipped";
                break;

            case ResultState.Success:
                testCase.result = "Success";
                break;
            }

            return(testCase);
        }
        /// <summary>
        /// Executes the NUnit test case
        /// </summary>
        /// <param name="result">The test case result</param>
        public override void Run(TestResult result)
        {
            const string METHOD_NAME = "Run: ";

            try
            {
                //Call the base method to log the result within NUnit
                testMethod.Run(result);

                //Get the URL, Login, Password and ProjectId from the parent test fixture attribute
                Type      type      = testMethod.FixtureType;
                Attribute attribute = Reflect.GetAttribute(type, "Inflectra.SpiraTest.AddOns.SpiraTestNUnitAddIn.SpiraTestFramework.SpiraTestConfigurationAttribute", false);
                if (attribute == null)
                {
                    throw new Exception("Cannot retrieve the SpiraTestConfiguration attribute from the test fixture");
                }

                //Get the various properties from the attribute
                string         url       = (string)Reflect.GetPropertyValue(attribute, "Url", BindingFlags.Public | BindingFlags.Instance);
                string         login     = (string)Reflect.GetPropertyValue(attribute, "Login", BindingFlags.Public | BindingFlags.Instance);
                string         password  = (string)Reflect.GetPropertyValue(attribute, "Password", BindingFlags.Public | BindingFlags.Instance);
                int            projectId = (int)Reflect.GetPropertyValue(attribute, "ProjectId", BindingFlags.Public | BindingFlags.Instance);
                Nullable <int> releaseId = null;
                if (Reflect.GetPropertyValue(attribute, "ReleaseId", BindingFlags.Public | BindingFlags.Instance) != null)
                {
                    releaseId = (Nullable <int>)Reflect.GetPropertyValue(attribute, "ReleaseId", BindingFlags.Public | BindingFlags.Instance);
                }
                Nullable <int> testSetId = null;
                if (Reflect.GetPropertyValue(attribute, "TestSetId", BindingFlags.Public | BindingFlags.Instance) != null)
                {
                    testSetId = (Nullable <int>)Reflect.GetPropertyValue(attribute, "TestSetId", BindingFlags.Public | BindingFlags.Instance);
                }
                string runnerName = Reflect.GetPropertyValue(attribute, "Runner", BindingFlags.Public | BindingFlags.Instance).ToString();

                //Now we need to extract the result information
                int executionStatusId = -1;
                if (!result.Executed)
                {
                    //Set status to 'Not Run'
                    executionStatusId = 3;
                }
                else
                {
                    //If no codes are found, default to blocked;
                    executionStatusId = 5;
                    if (result.IsFailure)
                    {
                        //Set status to 'Failed'
                        executionStatusId = 1;
                    }
                    if (result.IsSuccess)
                    {
                        //Set status to 'Passed'
                        executionStatusId = 2;
                    }
                    if (result.IsError)
                    {
                        //Set status to 'Failed'
                        executionStatusId = 1;
                    }
                }

                //Extract the other information
                string   testCaseName = result.Name;
                string   message      = result.Message;
                string   stackTrace   = result.StackTrace;
                int      assertCount  = result.AssertCount;
                DateTime startDate    = DateTime.Now.AddSeconds(-result.Time);
                DateTime endDate      = DateTime.Now;

                //Specify that we will be using TLS 1.2 if this is HTTPS
                System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

                //Instantiate the web-service proxy class and set the URL from the text box
                bool success = false;
                SpiraImportExport.ImportExport spiraTestExecuteProxy = new SpiraImportExport.ImportExport();
                spiraTestExecuteProxy.Url = url + TEST_EXECUTE_WEB_SERVICES_URL;

                //Create a new cookie container to hold the session handle
                CookieContainer cookieContainer = new CookieContainer();
                spiraTestExecuteProxy.CookieContainer = cookieContainer;

                //Attempt to authenticate the user
                success = spiraTestExecuteProxy.Connection_Authenticate(login, password);
                if (!success)
                {
                    throw new Exception("Cannot authenticate with SpiraTest, check the URL, login and password");
                }

                //Now connect to the specified project
                success = spiraTestExecuteProxy.Connection_ConnectToProject(projectId);
                if (!success)
                {
                    throw new Exception("Cannot connect to the specified project, check permissions of user!");
                }

                //Now actually record the test run itself
                SpiraImportExport.RemoteTestRun remoteTestRun = new SpiraImportExport.RemoteTestRun();
                remoteTestRun.TestCaseId        = testCaseId;
                remoteTestRun.ReleaseId         = releaseId;
                remoteTestRun.TestSetId         = testSetId;
                remoteTestRun.StartDate         = startDate;
                remoteTestRun.EndDate           = endDate;
                remoteTestRun.ExecutionStatusId = executionStatusId;
                remoteTestRun.RunnerName        = runnerName;
                remoteTestRun.RunnerTestName    = testCaseName;
                remoteTestRun.RunnerAssertCount = assertCount;
                remoteTestRun.RunnerMessage     = message;
                remoteTestRun.RunnerStackTrace  = stackTrace;
                spiraTestExecuteProxy.TestRun_RecordAutomated1(remoteTestRun);

                //Close the SpiraTest connection
                spiraTestExecuteProxy.Connection_Disconnect();
            }
            catch (Exception exception)
            {
                //Log error then rethrow
                System.Diagnostics.EventLog.WriteEntry(SpiraTestAddin.SOURCE_NAME, CLASS_NAME + METHOD_NAME + exception.Message, System.Diagnostics.EventLogEntryType.Error);
                throw exception;
            }
        }