예제 #1
0
        protected override void ExecuteTask()
        {
            int TestCount        = 0;
            int TestPassingCount = 0;

            foreach (String Fixture in Fixtures)
            {
                SubProject FixtureProject = this.Project.SubProjects[Fixture];

                try
                {
                    this.TryRun(string.Format("{0}.{1}", FixtureProject.ProjectName, FixtureSetUp), FixtureProject);

                    foreach (Target FixtureTarget in FixtureProject.Targets)
                    {
                        if (FixtureTarget.Name.EndsWith("Test"))
                        {
                            try
                            {
                                TestCount++;
                                this.TryRun(string.Format("{0}.{1}", FixtureProject.ProjectName, SetUpName), FixtureProject);
                                FixtureTarget.Execute();
                                TestPassingCount++;
                            }
                            catch (BuildException bx)
                            {
                                Log(Level.Error, "{0} at:{1}{2}", bx.Message, Environment.NewLine, bx.Location.ToString());
                            }
                            catch (Exception ex)
                            {
                                Log(Level.Error, "{0} in {1}", ex.Message, FixtureTarget.Name);
                            }
                            finally
                            {
                                this.TryRun(string.Format("{0}.{1}", FixtureProject.ProjectName, TearDownName), FixtureProject);
                            }
                        }
                    }
                }
                finally
                {
                    this.TryRun(string.Format("{0}.{1}", FixtureProject.ProjectName, FixtureTearDown), FixtureProject);
                }
            }

            int TestFailingCount = TestCount - TestPassingCount;

            Log(Level.Info, "Tests Run: {0}", TestCount);
            Log(Level.Info, "Tests Passing: {0}", TestPassingCount);
            Log(Level.Info, "Tests Failing: {0}", TestFailingCount);
            Log(Level.Info, "Test Assertions Executed: {0}", MbUnit.Framework.Assert.AssertCount);
            if (TestFailingCount > 0)
            {
                throw new BuildException(string.Format("{0} tests failed.", TestFailingCount));
            }
        }
예제 #2
0
        protected override void ExecuteTask()
        {
            int           TestCount        = 0;
            int           TestPassingCount = 0;
            StringBuilder FailingTestInfo  = new StringBuilder();

            ReportContainer Report = new ReportContainer();


            foreach (String Fixture in Fixtures)
            {
                if (!this.Project.ScriptFileInfoList.Contains(Fixture))
                {
                    throw new BuildException(string.Format("There is no fixture loaded for {0}.", Fixture), this.Location);
                }
                ScriptFileInfo FixtureProject = this.Project.ScriptFileInfoList[Fixture];

                FixtureReport fixtureReport = new FixtureReport(Fixture);
                Report.FixtureReports.Add(fixtureReport);

                try
                {
                    this.TryRun(string.Format("{0}.{1}", FixtureProject.ProjectName, FixtureSetUp), FixtureProject);

                    foreach (Target FixtureTarget in FixtureProject.Targets)
                    {
                        if (FixtureTarget.Name.EndsWith("Test"))
                        {
                            TestReport testReport = new TestReport(FixtureTarget.Name);
                            fixtureReport.TestReports.Add(testReport);
                            try
                            {
                                TestCount++;
                                this.TryRun(string.Format("{0}.{1}", FixtureProject.ProjectName, SetUpName), FixtureProject);
                                FixtureTarget.Execute();
                                TestPassingCount++;
                                testReport.Passed = true;
                            }
                            catch (BuildException bx)
                            {
                                string FailureInfo = string.Format("{0} at:{1}{2}{3}{4}", bx.Message, Environment.NewLine, bx.Location.ToString(), Environment.NewLine, bx.ToString());
                                Log(Level.Error, FailureInfo);
                                FailingTestInfo.AppendLine(FailureInfo);

                                testReport.Passed           = false;
                                testReport.FailureException = bx.ToString();
                            }
                            catch (Exception ex)
                            {
                                string FailureInfo = string.Format("{0} in {1}{2}{3}", ex.Message, FixtureTarget.Name, Environment.NewLine, ex.ToString());
                                Log(Level.Error, FailureInfo);
                                FailingTestInfo.AppendLine(FailureInfo);

                                testReport.Passed           = false;
                                testReport.FailureException = ex.ToString();
                            }
                            finally
                            {
                                this.TryRun(string.Format("{0}.{1}", FixtureProject.ProjectName, TearDownName), FixtureProject);
                            }
                        }
                    }
                }
                finally
                {
                    this.TryRun(string.Format("{0}.{1}", FixtureProject.ProjectName, FixtureTearDown), FixtureProject);
                }
            }

            int TestFailingCount = TestCount - TestPassingCount;

            Log(Level.Info, "Tests Run: {0}", TestCount);
            Log(Level.Info, "Tests Passing: {0}", TestPassingCount);
            Log(Level.Info, "Tests Failing: {0}", TestFailingCount);
            Log(Level.Info, "Test Assertions Executed: {0}", MbUnit.Framework.Assert.AssertCount);
            Console.WriteLine(FailingTestInfo.ToString());

            if (File.Exists(FilePath))
            {
                File.Delete(FilePath);
            }

            XmlSerializer Serializer = new XmlSerializer(typeof(ReportContainer));

            using (FileStream ReportStream = File.OpenWrite(FilePath))
            {
                Serializer.Serialize(ReportStream, Report);
            }

            if (TestFailingCount > 0)
            {
                throw new BuildException(string.Format("{0} tests failed.", TestFailingCount));
            }
        }