Ejemplo n.º 1
0
        //private readonly TestReportCollection _report;
        public NUnitXmlReport(TestReportCollection report)
        {
            if (report == null)
                throw new ArgumentNullException("report");

            //_report = report;
        }
Ejemplo n.º 2
0
        public void Should_conform_to_xml_schema()
        {
            string tempFileName = Path.GetTempFileName();
            try
            {
                var report = new TestReportCollection();
                var testReport = new TestReport(@"C:\Test.xap");
                testReport.AddResult(TestCaseResultFactory.CreatePassed());
                testReport.AddResult(TestCaseResultFactory.CreateFailed());
                testReport.AddResult(TestCaseResultFactory.CreateIgnored());

                report.Add(testReport);
                var trxReport = new TRXReport(report);
                trxReport.WriteXmlReport(tempFileName);

                File.ReadAllText(tempFileName).Trace();

                string xmlSchemaPath = @"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Xml\Schemas\vstst.xsd";
                IList<string> validationErrors = new List<string>();
                XmlSchemaValidatorHelper.ValidateSchema(tempFileName, File.ReadAllText(xmlSchemaPath), out validationErrors);

                foreach (var validationError in validationErrors)
                {
                    validationError.Trace();
                }

                validationErrors.Count.ShouldEqual(0);
            }
            catch (Exception)
            {
                if(File.Exists(tempFileName))
                    File.Delete(tempFileName);
                throw;
            }
        }
Ejemplo n.º 3
0
        private static void WriteXmlReport(TestReportCollection testReports, string xmlReportOutputPath, XmlReportType xmlReportType)
        {
            if (!string.IsNullOrEmpty(xmlReportOutputPath))
            {
                IXmlReport xmlReport = null;
                switch (xmlReportType)
                {
                case XmlReportType.TFS:
                    xmlReport = new Core.Reporting.Providers.TFS.TFS2010.XmlReport(testReports);
                    break;

                case XmlReportType.StatLight:
                    xmlReport = new XmlReport(testReports);
                    break;

                default:
                    throw new StatLightException("Unknown XmlReportType chosen Name=[{0}], Value=[{1}]".FormatWith(xmlReportType.ToString(), (int)xmlReportType));
                }

                xmlReport.WriteXmlReport(xmlReportOutputPath);

                "*********************************"
                .WrapConsoleMessageWithColor(Settings.Default.ConsoleColorInformatoin, true);

                "Wrote XML report to:{0}{1}"
                .FormatWith(Environment.NewLine, new FileInfo(xmlReportOutputPath).FullName)
                .WrapConsoleMessageWithColor(Settings.Default.ConsoleColorWarning, true);

                "*********************************"
                .WrapConsoleMessageWithColor(Settings.Default.ConsoleColorInformatoin, true);
            }
        }
Ejemplo n.º 4
0
        public TRXReport(TestReportCollection report)
        {
            if (report == null)
                throw new ArgumentNullException("report");

            _report = report;
        }
Ejemplo n.º 5
0
        public XmlReport(TestReportCollection report)
        {
            if (report == null)
            {
                throw new ArgumentNullException("report");
            }

            _report = report;
        }
Ejemplo n.º 6
0
        public TRXReport(TestReportCollection report, IGuidSequenceGenerator guidSequenceGenerator, TestSettings testSettings)
        {
            if (report == null)
                throw new ArgumentNullException("report");

            _report = report;
            _guidSequenceGenerator = guidSequenceGenerator;
            _testSettings = testSettings;
        }
Ejemplo n.º 7
0
        public TRXReport(TestReportCollection report, IGuidSequenceGenerator guidSequenceGenerator, TestSettings testSettings)
        {
            if (report == null)
            {
                throw new ArgumentNullException("report");
            }

            _report = report;
            _guidSequenceGenerator = guidSequenceGenerator;
            _testSettings          = testSettings;
        }
Ejemplo n.º 8
0
        public TestReportCollection Run()
        {
            RunnerType runnerType = DetermineRunnerType(_inputOptions.ContinuousIntegrationMode, _inputOptions.OutputForTeamCity, _inputOptions.StartWebServerOnly, _inputOptions.UseRemoteTestPage);

            _logger.Debug("RunnerType = {0}".FormatWith(runnerType));

            TestReportCollection testReports = GetTestReports(runnerType);

            WriteXmlReport(testReports, _inputOptions.ReportOutputPath, _inputOptions.ReportOutputFileType);

            return(testReports);
        }
Ejemplo n.º 9
0
        public void Should_spit_out_valid_MSTest_trx()
        {
            var report     = new TestReportCollection();
            var testReport = new TestReport(@"C:\Test.xap");

            testReport.AddResult(TestCaseResultFactory.CreatePassed());
            testReport.AddResult(TestCaseResultFactory.CreateFailed());
            //testReport.AddResult(TestCaseResultFactory.CreateIgnored());
            report.Add(testReport);

            report
            .AllTests()
            .Where(w => w.ResultType == ResultType.Failed)
            .Each(x => x.ExceptionInfo.StackTrace = "Some message that will be a stacktrace");

            var testSettings = new TestSettings();

            testSettings.ComputerName = "UserName-LT3";
            var trxReport = new TRXReport(report, new MockGuidSequenceGenerator(), testSettings);
            var output    = trxReport.GetXmlReport();

            var memoryStream = new MemoryStream();

            using (var writer = new StreamWriter(memoryStream))
            {
                var xml = output;
                xml.Save(writer);
                writer.Close();
            }

            string fileData         = memoryStream.ToArray().ToStringFromByteArray();
            string expectedFileData = Resources.SampleTRX_GeneratedFromRealTest.Trim();

            // replace the hard coded credentials with the current domain and user name
            expectedFileData = expectedFileData.Replace(@"DOMAIN\UserName", string.Format(@"{0}\{1}", Environment.UserDomainName, Environment.UserName));

            FixupRegEx("duration=\"00:00:00.0000000\"", ref expectedFileData, ref fileData,
                       @"duration=\""[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\.[0-9][0-9][0-9][0-9][0-9][0-9][0-9]\""");

            FixupRegEx("startTime=\"0000-00-00T00:00:00.0000000-00:00\"", ref expectedFileData, ref fileData,
                       @"startTime=\""[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9][0-9][0-9][0-9][0-9][-+][0-9][0-9]:[0-9][0-9]\""");

            FixupRegEx("endTime=\"0000-00-00T00:00:00.0000000-00:00\"", ref expectedFileData, ref fileData,
                       @"endTime=\""[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9][0-9][0-9][0-9][0-9][-+][0-9][0-9]:[0-9][0-9]\""");

            //fileData.Trace();
            //expectedFileData.Trace();
            fileData.ShouldEqual(expectedFileData);
        }
Ejemplo n.º 10
0
        private void TryRun()
        {
            _isRunning = true;
            var       testReportCollection = new TestReportCollection();
            Stopwatch multiRunStopwatch    = Stopwatch.StartNew();

            while (_queuedRuns.Count > 0)
            {
                XapFileBuildChangedServerEvent buildEvent;

                lock (_sync)
                {
                    buildEvent = _queuedRuns.Dequeue();
                }

                var xapPath = buildEvent.XapPath;

                _currentStatLightConfiguration.SetCurrentTo(xapPath);

                _currentStatLightConfiguration.Current.Client.TagFilter = _currentFilterString;

                using (var onetimeRunner = new OnetimeRunner(
                           logger: _logger,
                           eventSubscriptionManager: _eventSubscriptionManager,
                           eventPublisher: _eventPublisher,
                           webServer: _webServer,
                           webBrowsers: _webBrowsers,
                           xapPath: xapPath,
                           dialogMonitorRunner: _dialogMonitorRunner))
                {
                    Stopwatch  singleRunStopwatch = Stopwatch.StartNew();
                    TestReport testReport         = onetimeRunner.Run();
                    singleRunStopwatch.Stop();
                    testReportCollection.Add(testReport);
                    _eventPublisher.SendMessage(new TestReportGeneratedServerEvent(testReport, singleRunStopwatch.Elapsed, shouldPrintSummary: _statLightConfigurations.Count > 1));
                }
            }

            multiRunStopwatch.Stop();
            _isRunning = false;

            if (testReportCollection.Any())
            {
                _eventPublisher.SendMessage(new TestReportCollectionGeneratedServerEvent(testReportCollection, multiRunStopwatch.Elapsed));
            }
        }
Ejemplo n.º 11
0
        public void Should_spit_out_valid_MSTest_trx()
        {
            var report = new TestReportCollection();
            var testReport = new TestReport(@"C:\Test.xap");
            testReport.AddResult(TestCaseResultFactory.CreatePassed());
            testReport.AddResult(TestCaseResultFactory.CreateFailed());
            //testReport.AddResult(TestCaseResultFactory.CreateIgnored());
            report.Add(testReport);

            report
                .AllTests()
                .Where(w => w.ResultType == ResultType.Failed)
                .Each(x => x.ExceptionInfo.StackTrace = "Some message that will be a stacktrace");

            var testSettings = new TestSettings();
            testSettings.ComputerName = "UserName-LT3";
            var trxReport = new TRXReport(report, new MockGuidSequenceGenerator(), testSettings);
            var output = trxReport.GetXmlReport();

            var memoryStream = new MemoryStream();
            using (var writer = new StreamWriter(memoryStream))
            {
                var xml = output;
                xml.Save(writer);
                writer.Close();
            }

            string fileData = memoryStream.ToArray().ToStringFromByteArray();
            string expectedFileData = Resources.SampleTRX_GeneratedFromRealTest;

            FixupRegEx("duration=\"00:00:00.0000000\"", ref expectedFileData, ref fileData,
                @"duration=\""[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\.[0-9][0-9][0-9][0-9][0-9][0-9][0-9]\""");

            FixupRegEx("startTime=\"0000-00-00T00:00:00.0000000-00:00\"", ref expectedFileData, ref fileData,
                @"startTime=\""[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9]:[0-9][0-9]\""");

            FixupRegEx("endTime=\"0000-00-00T00:00:00.0000000-00:00\"", ref expectedFileData, ref fileData,
                @"endTime=\""[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9]:[0-9][0-9]\""");

            //fileData.Trace();
            //expectedFileData.Trace();
            fileData.ShouldEqual(expectedFileData);
        }
Ejemplo n.º 12
0
        public void Should_conform_to_xml_schema()
        {
            string tempFileName = Path.GetTempFileName();

            try
            {
                var report     = new TestReportCollection();
                var testReport = new TestReport(@"C:\Test.xap");
                testReport.AddResult(TestCaseResultFactory.CreatePassed());
                //testReport.AddResult(TestCaseResultFactory.CreateFailed());
                //testReport.AddResult(TestCaseResultFactory.CreateIgnored());

                report.Add(testReport);
                var trxReport = new TRXReport(report);
                trxReport.WriteXmlReport(tempFileName);

                //File.ReadAllText(tempFileName).Trace();

                var            xmlSchema = Resources.vstst;
                IList <string> validationErrors;
                XmlSchemaValidatorHelper.ValidateSchema(tempFileName, xmlSchema, out validationErrors);

                tempFileName.Trace();

                foreach (var validationError in validationErrors)
                {
                    validationError.Trace();
                }

                if (validationErrors.Any())
                {
                    Assert.Fail("Validation Errors:{0}{1}".FormatWith(Environment.NewLine, string.Join(Environment.NewLine, validationErrors)));
                }
            }
            catch (Exception)
            {
                if (File.Exists(tempFileName))
                {
                    File.Delete(tempFileName);
                }
                throw;
            }
        }
Ejemplo n.º 13
0
        private TestReportCollection GetTestReports(RunnerType runnerType)
        {
            var testReports = new TestReportCollection();

            IEnumerable <StatLightConfiguration> statLightConfigurations = _currentStatLightConfiguration.ToList();

            if (runnerType == RunnerType.ContinuousTest)
            {
                IRunner continuousTestRunner = _statLightRunnerFactory.CreateContinuousTestRunner(statLightConfigurations);
                continuousTestRunner.Run();
            }
            else
            {
                Stopwatch totalTime = Stopwatch.StartNew();

                do
                {
                    using (IRunner runner = GetRunner(
                               _logger,
                               runnerType,
                               _currentStatLightConfiguration.Current,
                               _statLightRunnerFactory))
                    {
                        _logger.Debug("IRunner typeof({0})".FormatWith(runner.GetType().Name));
                        Stopwatch  stopwatch  = Stopwatch.StartNew();
                        TestReport testReport = runner.Run();
                        stopwatch.Stop();
                        testReports.Add(testReport);
                        _eventPublisher.SendMessage(new TestReportGeneratedServerEvent(testReport, stopwatch.Elapsed,
                                                                                       statLightConfigurations.Count() >
                                                                                       1));
                    }
                } while (_currentStatLightConfiguration.MoveNext());

                totalTime.Stop();

                _eventPublisher.SendMessage(new TestReportCollectionGeneratedServerEvent(testReports, totalTime.Elapsed));
            }

            return(testReports);
        }
Ejemplo n.º 14
0
        public void Should_conform_to_xml_schema()
        {
            string tempFileName = Path.GetTempFileName();
            try
            {
                var report = new TestReportCollection();
                var testReport = new TestReport(@"C:\Test.xap");
                testReport.AddResult(TestCaseResultFactory.CreatePassed());
                //testReport.AddResult(TestCaseResultFactory.CreateFailed());
                //testReport.AddResult(TestCaseResultFactory.CreateIgnored());

                report.Add(testReport);
                var trxReport = new TRXReport(report);
                trxReport.WriteXmlReport(tempFileName);

                //File.ReadAllText(tempFileName).Trace();

                var xmlSchema = Resources.vstst;
                IList<string> validationErrors;
                XmlSchemaValidatorHelper.ValidateSchema(tempFileName, xmlSchema, out validationErrors);

                tempFileName.Trace();

                foreach (var validationError in validationErrors)
                {
                    validationError.Trace();
                }

                if (validationErrors.Any())
                {
                    Assert.Fail("Validation Errors:{0}{1}".FormatWith(Environment.NewLine, string.Join(Environment.NewLine, validationErrors)));
                }
            }
            catch (Exception)
            {
                if(File.Exists(tempFileName))
                    File.Delete(tempFileName);
                throw;
            }
        }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
            {
                Console.WriteLine(e.ExceptionObject);
            };
            PrintNameVersionAndCopyright();

            ArgOptions options;

            using (var consoleIconSwapper = new ConsoleIconSwapper())
            {
                consoleIconSwapper.ShowConsoleIcon(CoreResources.FavIcon);

                try
                {
                    options = new ArgOptions(args);

                    if (options.ShowHelp)
                    {
                        ArgOptions.ShowHelpMessage(Console.Out, options);
                        return;
                    }

                    if (!options.XapPaths.Any() && !options.Dlls.Any())
                    {
                        throw new StatLightException("No xap or silverlight dll's specified.");
                    }

                    ILogger logger = GetLogger(options.IsRequestingDebug);

                    var commandLineExecutionEngine   = new CommandLineExecutionEngine(logger, options);
                    TestReportCollection testReports = commandLineExecutionEngine.Run();

                    if (testReports.FinalResult == RunCompletedState.Failure)
                    {
                        Environment.ExitCode = ExitFailed;
                    }
                    else
                    {
                        Environment.ExitCode = ExitSucceeded;
                    }
                }
                catch (AddressAccessDeniedException addressAccessDeniedException)
                {
                    Environment.ExitCode = ExitFailed;
                    var helpMessage = @"
Cannot run StatLight. The current account does not have the correct privilages.

Exception:
{0}

Try: (the following two steps that should allow StatLight to start a web server on the requested port)
     1. Run cmd.exe as Administrator.
     2. Enter the following command in the command prompt.
          netsh http add urlacl url=http://+:8887/ user=DOMAIN\user
".FormatWith(addressAccessDeniedException.Message);

                    WriteErrorToConsole(helpMessage, "Error");
                }
                catch (FileNotFoundException fileNotFoundException)
                {
                    HandleKnownError(fileNotFoundException);
                }
                catch (StatLightException statLightException)
                {
                    HandleKnownError(statLightException);
                }

                catch (Exception exception)
                {
                    HandleUnknownError(exception);
                }
            }
        }
Ejemplo n.º 16
0
        public TestReportCollection Run()
        {
            bool showTestingBrowserHost       = _options.ShowTestingBrowserHost;
            bool useRemoteTestPage            = _options.UseRemoteTestPage;
            Collection <string> methodsToTest = _options.MethodsToTest;
            MicrosoftTestingFrameworkVersion?microsoftTestingFrameworkVersion = _options.MicrosoftTestingFrameworkVersion;
            string tagFilters = _options.TagFilters;
            UnitTestProviderType unitTestProviderType = _options.UnitTestProviderType;
            int            numberOfBrowserHosts       = _options.NumberOfBrowserHosts;
            string         queryString       = _options.QueryString;
            WebBrowserType webBrowserType    = _options.WebBrowserType;
            bool           forceBrowserStart = _options.ForceBrowserStart;

            IEnumerable <string> xapPaths = _options.XapPaths;
            IEnumerable <string> testDlls = _options.Dlls;

            _options.DumpValuesForDebug(_logger);

            var runnerType = GetRunnerType();

            _logger.Debug("RunnerType = {0}".FormatWith(runnerType));

            var testReports = new TestReportCollection();

            foreach (var xapPath in xapPaths)
            {
                _logger.Debug("Starting configuration for: {0}".FormatWith(xapPath));
                StatLightConfiguration statLightConfiguration = _statLightConfigurationFactory
                                                                .GetStatLightConfigurationForXap(
                    unitTestProviderType,
                    xapPath,
                    microsoftTestingFrameworkVersion,
                    methodsToTest,
                    tagFilters,
                    numberOfBrowserHosts,
                    useRemoteTestPage,
                    queryString,
                    webBrowserType,
                    forceBrowserStart,
                    showTestingBrowserHost);

                var testReport = DoTheRun(runnerType, statLightConfiguration);
                testReports.Add(testReport);
            }

            foreach (var dllPath in testDlls)
            {
                _logger.Debug("Starting configuration for: {0}".FormatWith(dllPath));
                StatLightConfiguration statLightConfiguration = _statLightConfigurationFactory
                                                                .GetStatLightConfigurationForDll(
                    unitTestProviderType,
                    dllPath,
                    microsoftTestingFrameworkVersion,
                    methodsToTest,
                    tagFilters,
                    numberOfBrowserHosts,
                    useRemoteTestPage,
                    queryString,
                    webBrowserType,
                    forceBrowserStart,
                    showTestingBrowserHost);

                var testReport = DoTheRun(runnerType, statLightConfiguration);
                testReports.Add(testReport);
            }

            string        xmlReportOutputPath = _options.XmlReportOutputPath;
            bool          tfsGenericReport    = _options.TFSGenericReport;
            XmlReportType xmlReportType       = XmlReportType.StatLight;

            if (tfsGenericReport)
            {
                xmlReportType = XmlReportType.TFS;
            }

            WriteXmlReport(testReports, xmlReportOutputPath, xmlReportType);

            return(testReports);
        }
Ejemplo n.º 17
0
 private static IEnumerable<TestCaseResult> GetTRXTests(TestReportCollection testReportCollection)
 {
     return testReportCollection
         .AllTests()
         .Where(w => w.ResultType != ResultType.Ignored);
 }
Ejemplo n.º 18
0
 public TRXReport(TestReportCollection report)
     : this(report, new GuidSequenceGenerator(), new TestSettings())
 {
 }
Ejemplo n.º 19
0
        private XElement GetResults(TestReportCollection results, XNamespace ns)
        {
            Func <ResultType, string> getResult = r =>
            {
                if (r == ResultType.Failed)
                {
                    return("Failed");
                }
                if (r == ResultType.SystemGeneratedFailure)
                {
                    return("Failed");
                }
                if (r == ResultType.Passed)
                {
                    return("Passed");
                }

                if (r == ResultType.Ignored)
                {
                    throw new StatLightException("TRX doesn't have an Ignored type - this test should have not come up and should be - haha 'Ignored'.");
                }

                throw new NotImplementedException("Unknown result type [{0}]".FormatWith(r.ToString()));
            };


            Func <TestCaseResultServerEvent, XElement> getOutput = test =>
            {
                Func <Func <ExceptionInfo, string>, string> getExceptionInfo = (getter) =>
                {
                    if (test.ExceptionInfo == null)
                    {
                        return("");
                    }

                    return(getter(test.ExceptionInfo) ?? "");
                };

                Func <string> getOtherInfo = () =>
                {
                    if (string.IsNullOrEmpty(test.OtherInfo))
                    {
                        return("");
                    }

                    return(Environment.NewLine + "Other Info: " + test.OtherInfo);
                };

                if (test.ResultType == ResultType.Failed || test.ResultType == ResultType.SystemGeneratedFailure)
                {
                    return(new XElement(ns + "Output"
                                        , new XElement(ns + "ErrorInfo"
                                                       , new XElement(ns + "Message"
                                                                      ,
                                                                      getExceptionInfo(x => x.Message) + getOtherInfo())
                                                       , new XElement(ns + "StackTrace"
                                                                      , getExceptionInfo(x => x.StackTrace))
                                                       )));
                }
                return(null);
            };

            return(new XElement(ns + "Results",
                                from test in GetTRXTests(results)
                                select new XElement(ns + "UnitTestResult"
                                                    , new XAttribute("executionId", GetExecutionId(test))
                                                    , new XAttribute("testId", GetTestId(test))
                                                    , new XAttribute("testName", test.MethodName)
                                                    , new XAttribute("computerName", _testSettings.ComputerName)
                                                    , new XAttribute("duration", test.TimeToComplete.ToString("hh\\:mm\\:ss\\.fffffff"))
                                                    , new XAttribute("startTime", test.Started.ToString("yyyy-MM-ddThh:mm:ss.fffffffK"))
                                                    , new XAttribute("endTime", (test.Finished ?? new DateTime()).ToString("yyyy-MM-ddThh:mm:ss.fffffffK"))
                                                    , new XAttribute("testType", _testSettings.TestType)
                                                    , new XAttribute("outcome", getResult(test.ResultType))
                                                    , new XAttribute("testListId", _testListId)
                                                    , new XAttribute("relativeResultsDirectory", GetExecutionId(test))
                                                    , getOutput(test)
                                                    )
                                ));
        }
Ejemplo n.º 20
0
 private static IEnumerable <TestCaseResultServerEvent> GetTRXTests(TestReportCollection testReportCollection)
 {
     return(testReportCollection
            .AllTests()
            .Where(w => w.ResultType != ResultType.Ignored));
 }
Ejemplo n.º 21
0
 public TestReportCollectionGeneratedServerEvent(TestReportCollection testReportCollection, TimeSpan totalTime)
 {
     TestReportCollection = testReportCollection;
     TotalTime            = totalTime;
 }
Ejemplo n.º 22
0
        public TestReportCollection Run()
        {
            bool showTestingBrowserHost = _options.ShowTestingBrowserHost;
            bool useRemoteTestPage = _options.UseRemoteTestPage;
            Collection<string> methodsToTest = _options.MethodsToTest;
            MicrosoftTestingFrameworkVersion? microsoftTestingFrameworkVersion = _options.MicrosoftTestingFrameworkVersion;
            string tagFilters = _options.TagFilters;
            UnitTestProviderType unitTestProviderType = _options.UnitTestProviderType;
            int numberOfBrowserHosts = _options.NumberOfBrowserHosts;
            string queryString = _options.QueryString;
            WebBrowserType webBrowserType = _options.WebBrowserType;
            bool forceBrowserStart = _options.ForceBrowserStart;

            IEnumerable<string> xapPaths = _options.XapPaths;
            IEnumerable<string> testDlls = _options.Dlls;

            _options.DumpValuesForDebug(_logger);

            var runnerType = GetRunnerType();

            _logger.Debug("RunnerType = {0}".FormatWith(runnerType));

            var testReports = new TestReportCollection();

            foreach (var xapPath in xapPaths)
            {
                _logger.Debug("Starting configuration for: {0}".FormatWith(xapPath));
                StatLightConfiguration statLightConfiguration = _statLightConfigurationFactory
                    .GetStatLightConfigurationForXap(
                        unitTestProviderType,
                        xapPath,
                        microsoftTestingFrameworkVersion,
                        methodsToTest,
                        tagFilters,
                        numberOfBrowserHosts,
                        useRemoteTestPage,
                        queryString,
                        webBrowserType,
                        forceBrowserStart,
                        showTestingBrowserHost);

                var testReport = DoTheRun(runnerType, statLightConfiguration);
                testReports.Add(testReport);
            }

            foreach (var dllPath in testDlls)
            {
                _logger.Debug("Starting configuration for: {0}".FormatWith(dllPath));
                StatLightConfiguration statLightConfiguration = _statLightConfigurationFactory
                    .GetStatLightConfigurationForDll(
                        unitTestProviderType,
                        dllPath,
                        microsoftTestingFrameworkVersion,
                        methodsToTest,
                        tagFilters,
                        numberOfBrowserHosts,
                        useRemoteTestPage,
                        queryString,
                        webBrowserType,
                        forceBrowserStart,
                        showTestingBrowserHost);

                var testReport = DoTheRun(runnerType, statLightConfiguration);
                testReports.Add(testReport);
            }

            WriteXmlReport(testReports, _options.XmlReportOutputPath, _options.ReportOutputFileType);

            return testReports;
        }
Ejemplo n.º 23
0
        private static void WriteXmlReport(TestReportCollection testReports, string xmlReportOutputPath, ReportOutputFileType reportOutputFileType)
        {
            if (!string.IsNullOrEmpty(xmlReportOutputPath))
            {
                IXmlReport xmlReport;
                switch (reportOutputFileType)
                {
                    case ReportOutputFileType.MSGenericTest:
                        xmlReport = new Core.Reporting.Providers.TFS.TFS2010.MSGenericTestXmlReport(testReports);
                        break;
                    case ReportOutputFileType.StatLight:
                        xmlReport = new Core.Reporting.Providers.Xml.XmlReport(testReports);
                        break;
                    case ReportOutputFileType.NUnit:
                        xmlReport = new Core.Reporting.Providers.NUnit.NUnitXmlReport(testReports);
                        break;
                    default:
                        throw new StatLightException("Unknown ReportOutputFileType chosen Name=[{0}], Value=[{1}]".FormatWith(reportOutputFileType.ToString(), (int)reportOutputFileType));
                }

                xmlReport.WriteXmlReport(xmlReportOutputPath);

                "*********************************"
                    .WrapConsoleMessageWithColor(Settings.Default.ConsoleColorInformation, true);

                "Wrote XML report to:{0}{1}"
                    .FormatWith(Environment.NewLine, new FileInfo(xmlReportOutputPath).FullName)
                    .WrapConsoleMessageWithColor(Settings.Default.ConsoleColorWarning, true);

                "*********************************"
                    .WrapConsoleMessageWithColor(Settings.Default.ConsoleColorInformation, true);
            }
        }
Ejemplo n.º 24
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
            {
                Console.WriteLine(e.ExceptionObject);
            };

            PrintNameVersionAndCopyright();

            using (var consoleIconSwapper = new ConsoleIconSwapper())
            {
                consoleIconSwapper.ShowConsoleIcon(CoreResources.FavIcon);

                try
                {
                    var options = new ArgOptions(args);

                    if (options.ShowHelp)
                    {
                        ArgOptions.ShowHelpMessage(Console.Out, options);
                        return;
                    }

                    if (!options.XapPaths.Any() && !options.Dlls.Any())
                    {
                        throw new StatLightException("No xap or silverlight dll's specified.");
                    }

                    var inputOptions = new InputOptions()
                                       .SetWindowGeometry(options.WindowGeometry)
                                       .SetUseRemoteTestPage(options.UseRemoteTestPage)
                                       .SetMethodsToTest(options.MethodsToTest)
                                       .SetMicrosoftTestingFrameworkVersion(options.MicrosoftTestingFrameworkVersion)
                                       .SetTagFilters(options.TagFilters)
                                       .SetUnitTestProviderType(options.UnitTestProviderType)
                                       .SetNumberOfBrowserHosts(options.NumberOfBrowserHosts)
                                       .SetQueryString(options.QueryString)
                                       .SetWebBrowserType(options.WebBrowserType)
                                       .SetForceBrowserStart(options.ForceBrowserStart)
                                       .SetXapPaths(options.XapPaths)
                                       .SetDllPaths(options.Dlls)
                                       .SetReportOutputPath(options.XmlReportOutputPath)
                                       .SetReportOutputFileType(options.ReportOutputFileType)
                                       .SetContinuousIntegrationMode(options.ContinuousIntegrationMode)
                                       .SetOutputForTeamCity(options.OutputForTeamCity)
                                       .SetStartWebServerOnly(options.StartWebServerOnly)
                                       .SetIsRequestingDebug(options.IsRequestingDebug)
                    ;

                    TestReportCollection testReports = null;

                    try
                    {
                        TinyIoCContainer ioc = BootStrapper.Initialize(inputOptions);

                        var commandLineExecutionEngine = ioc.Resolve <RunnerExecutionEngine>();

                        testReports = commandLineExecutionEngine.Run();
                    }
                    catch (TinyIoCResolutionException tinyIoCResolutionException)
                    {
                        if (options.IsRequestingDebug)
                        {
                            throw;
                        }

                        throw ResolveNonTinyIocException(tinyIoCResolutionException);
                    }

                    if (testReports.FinalResult == RunCompletedState.Failure)
                    {
                        Environment.ExitCode = ExitFailed;
                    }
                    else
                    {
                        Environment.ExitCode = ExitSucceeded;
                    }
                }
                catch (AddressAccessDeniedException addressAccessDeniedException)
                {
                    Environment.ExitCode = ExitFailed;
                    var helpMessage = @"
Cannot run StatLight. The current account does not have the correct privilages.

Exception:
{0}

Try: (the following two steps that should allow StatLight to start a web server on the requested port)
     1. Run cmd.exe as Administrator.
     2. Enter the following command in the command prompt.
          netsh http add urlacl url=http://+:8887/ user=DOMAIN\user
".FormatWith(addressAccessDeniedException.Message);

                    WriteErrorToConsole(helpMessage, "Error");
                }
                catch (FileNotFoundException fileNotFoundException)
                {
                    HandleKnownError(fileNotFoundException);
                }
                catch (StatLightException statLightException)
                {
                    HandleKnownError(statLightException);
                }

                catch (Exception exception)
                {
                    HandleUnknownError(exception);
                }
            }
        }
Ejemplo n.º 25
0
 public TRXReport(TestReportCollection report)
     : this(report, new GuidSequenceGenerator(), new TestSettings())
 {
 }
Ejemplo n.º 26
0
 public TestReportCollectionGeneratedServerEvent(TestReportCollection testReportCollection, TimeSpan totalTime)
 {
     TestReportCollection = testReportCollection;
     TotalTime = totalTime;
 }
Ejemplo n.º 27
0
        private XElement GetResults(TestReportCollection results, XNamespace ns)
        {
            Func<ResultType, string> getResult = r =>
            {
                if (r == ResultType.Failed)
                    return "Failed";
                if (r == ResultType.SystemGeneratedFailure)
                    return "Failed";
                if (r == ResultType.Passed)
                    return "Passed";

                if (r == ResultType.Ignored)
                    throw new StatLightException("TRX doesn't have an Ignored type - this test should have not come up and should be - haha 'Ignored'.");

                throw new NotImplementedException("Unknown result type [{0}]".FormatWith(r.ToString()));
            };

            Func<TestCaseResult, XElement> getOutput = test =>
            {
                Func<Func<ExceptionInfo, string>, string> getExceptionInfo = (getter) =>
                {
                    if (test.ExceptionInfo == null)
                        return "";

                    return getter(test.ExceptionInfo) ?? "";
                };

                Func<string> getOtherInfo = () =>
                {
                    if (string.IsNullOrEmpty(test.OtherInfo))
                        return "";

                    return Environment.NewLine + "Other Info: " + test.OtherInfo;
                };

                if (test.ResultType == ResultType.Failed || test.ResultType == ResultType.SystemGeneratedFailure)
                {
                    return new XElement(ns + "Output"
                                        , new XElement(ns + "ErrorInfo"
                                                       , new XElement(ns + "Message"
                                                                      ,
                                                                      getExceptionInfo(x => x.Message) + getOtherInfo())
                                                       , new XElement(ns + "StackTrace"
                                                                      , getExceptionInfo(x => x.StackTrace))
                                              ));
                }
                return null;
            };

            return new XElement(ns + "Results",
                from test in GetTRXTests(results)
                select new XElement(ns + "UnitTestResult"
                    , new XAttribute("executionId", GetExecutionId(test))
                    , new XAttribute("testId", GetTestId(test))
                    , new XAttribute("testName", test.MethodName)
                    , new XAttribute("computerName", _testSettings.ComputerName)
                    , new XAttribute("duration", test.TimeToComplete.ToString("hh\\:mm\\:ss\\.fffffff"))
                    , new XAttribute("startTime", test.Started.ToString("yyyy-MM-ddThh:mm:ss.fffffffK"))
                    , new XAttribute("endTime", (test.Finished ?? new DateTime()).ToString("yyyy-MM-ddThh:mm:ss.fffffffK"))
                    , new XAttribute("testType", _testSettings.TestType)
                    , new XAttribute("outcome", getResult(test.ResultType))
                    , new XAttribute("testListId", _testListId)
                    , new XAttribute("relativeResultsDirectory", GetExecutionId(test))
                    , getOutput(test)
                )
            );
        }
Ejemplo n.º 28
0
 private XElement GetResultSummary(TestReportCollection results)
 {
     return new XElement("ResultSummary",
             new XAttribute("outcome", (results.FinalResult == RunCompletedState.Failure ? "Failed" : "Completed")),
             new XElement("Counters",
                 new XAttribute("total", results.TotalResults),
                 new XAttribute("executed", results.TotalResults),
                 new XAttribute("passed", results.TotalPassed),
                 new XAttribute("error", 0),
                 new XAttribute("failed", results.TotalFailed),
                 new XAttribute("timeout", 0),
                 new XAttribute("aborted", 0),
                 new XAttribute("inconclusive", 0),
                 new XAttribute("passedButRunAborted", 0),
                 new XAttribute("notRunnable", 0),
                 new XAttribute("notExecuted", 0),
                 new XAttribute("disconnected", 0),
                 new XAttribute("warning", 0),
                 new XAttribute("completed", 0),
                 new XAttribute("inProgress", 0),
                 new XAttribute("pending", 0)
                 )
         );
 }
Ejemplo n.º 29
0
        private TestReportCollection GetTestReports(RunnerType runnerType)
        {
            var testReports = new TestReportCollection();

            IEnumerable<StatLightConfiguration> statLightConfigurations = _currentStatLightConfiguration.ToList();

            if (runnerType == RunnerType.ContinuousTest)
            {
                IRunner continuousTestRunner = _statLightRunnerFactory.CreateContinuousTestRunner(statLightConfigurations);
                continuousTestRunner.Run();
            }
            else
            {

                Stopwatch totalTime = Stopwatch.StartNew();

                do
                {
                    using (IRunner runner = GetRunner(
                        _logger,
                        runnerType,
                        _currentStatLightConfiguration.Current,
                        _statLightRunnerFactory))
                    {
                        _logger.Debug("IRunner typeof({0})".FormatWith(runner.GetType().Name));
                        Stopwatch stopwatch = Stopwatch.StartNew();
                        TestReport testReport = runner.Run();
                        stopwatch.Stop();
                        testReports.Add(testReport);
                        _eventPublisher.SendMessage(new TestReportGeneratedServerEvent(testReport, stopwatch.Elapsed,
                                                                                       statLightConfigurations.Count() >
                                                                                       1));
                    }

                } while (_currentStatLightConfiguration.MoveNext());

                totalTime.Stop();

                _eventPublisher.SendMessage(new TestReportCollectionGeneratedServerEvent(testReports, totalTime.Elapsed));
            }

            return testReports;
        }