コード例 #1
0
        public void TotalVerificationsFailed_should_count_failed_tests()
        {
            // Arrange
            var builder = new TestCaseResultsBuilder()
                                .New().AddPositiveVerify().Add()
                                .New().AddPositiveVerify(false).Add()
                                .New().AddNegativeVerify(false).Add();

            var testSession = new TestCaseSession();
            testSession.TestCaseResults = builder.GetCollection();

            // Act + Assert
            Assert.That(testSession.TotalVerificationsFailed, Is.EqualTo(2));
        }
コード例 #2
0
        public void TotalCasesPassed_should_count_passed_tests()
        {
            // Arrange
            var builder = new TestCaseResultsBuilder()
                                .New().WithSuccess().Add()
                                .New().WithSuccess().Add()
                                .New().WithSuccess().Add()
                                .New().WithFail().Add()
                                .New().WithFail().Add();

            var testSession = new TestCaseSession();
            testSession.TestCaseResults = builder.GetCollection();

            // Act + Assert
            Assert.That(testSession.TotalCasesPassed, Is.EqualTo(3));
        }
コード例 #3
0
 private static void DumpAsYaml(TestCaseSession session)
 {
     var stringBuilder = new StringBuilder();
     var serializer = new Serializer();
     serializer.Serialize(new IndentedTextWriter(new StringWriter(stringBuilder)), session);
     Console.WriteLine(stringBuilder);
 }
コード例 #4
0
        private static void DumpAsXml(TestCaseSession session)
        {
            var stringBuilder = new StringBuilder();
            var serializer = new XmlSerializer(typeof (TestCaseSession));
            serializer.Serialize(new StringWriter(stringBuilder), session);

            Console.WriteLine(stringBuilder);
        }
コード例 #5
0
        public TestCaseSession Run(CaseCollection testCollection)
        {
            _isStopPending = false;
            _currentResults = new List<TestCaseResult>();

            var session = new TestCaseSession();
            session.StartTime = DateTime.UtcNow;

            // Add all config variables and ones in this <testcase>
            var variables = new SessionVariables();
            variables.AddGlobalVariables(_config);
            variables.AddOrUpdateVariables(testCollection.Variables);

            var verificationsMatcher = new VerificationsMatcher(variables);

            // Ensure we loop atleast once:
            int repeatTotal = (testCollection.Repeat > 0) ? testCollection.Repeat : 1;
            List<Case> testCases = testCollection.TestCases.ToList();

            TimeSpan minResponseTime = TimeSpan.MaxValue;
            TimeSpan maxResponseTime = TimeSpan.MinValue;
            int totalCasesRun = 0;

            CasesRun = 0;
            TotalCases = testCases.Count;
            RepeatCount = 0;

            for (int i = 0; i < repeatTotal; i++)
            {
                foreach (Case testCase in testCases)
                {
                    if (_isStopPending)
                        break;

                    try
                    {
                        TestCaseResult result = RunCase(testCase, variables, verificationsMatcher);
                        session.TestCaseResults.Add(result);
                        _currentResults.Add(result);

                        if (result.ResponseTime < minResponseTime)
                            minResponseTime = result.ResponseTime;

                        if (result.ResponseTime > maxResponseTime)
                            maxResponseTime = result.ResponseTime;
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex, "An exception occurred running case {0}", testCase.Id);
                    }
                    finally
                    {
                        totalCasesRun++;

                        CasesRun++;
                        RepeatCount = i;
                    }
                }

                if (_isStopPending)
                    break;
            }

            session.EndTime = DateTime.UtcNow;
            session.TotalRunTime = session.EndTime - session.StartTime;
            session.TotalCasesRun = totalCasesRun;
            session.MinResponseTime = minResponseTime;
            session.MaxResponseTime = maxResponseTime;

            return session;
        }