예제 #1
0
        public static void GenerateReport(string[] paths)
        {
            var reporter = ReporterFactory.Build(new EmptyTestDataProvider());
            var tests    = new List <KeyValuePair <TestRunDto, TestOutputDto> >();

            foreach (var path in paths)
            {
                var ext = Path.GetExtension(path)?.ToLower();
                switch (ext)
                {
                case ".xml":
                    tests.AddRange(GhprNUnitRunHelper.GetTestRunsListFromFile(path, reporter.Logger)
                                   .Select(g => new KeyValuePair <TestRunDto, TestOutputDto>(g.GhprTestRun, g.GhprTestOutput)).ToList());
                    break;

                case ".trx":
                    tests.AddRange(GhprMSTestV2RunHelper.GetTestRunsListFromFile(path)
                                   .Select(g => new KeyValuePair <TestRunDto, TestOutputDto>(g.GhprTestRun, g.GhprTestOutput)).ToList());
                    break;

                default:
                    Console.WriteLine($"Unsupported file extension: '{ext}' for file '{path}'. " +
                                      "Only '.xml' and '.trx' extensions supported.");
                    break;
                }
            }
            reporter.GenerateFullReport(tests);
            reporter.CleanUpJob();
            reporter.TearDown();
        }
예제 #2
0
        public void LoggerTest()
        {
            var e = new Exception();
            var o = new object();
            var r = ReporterFactory.Build(new MockTestDataProvider());

            Assert.DoesNotThrow(() => { r.Logger.SetUp(r.ReporterSettings); });
            Assert.DoesNotThrow(() => { r.Logger.Info(o, e); });
            Assert.DoesNotThrow(() => { r.Logger.Info("msg", e); });
            Assert.DoesNotThrow(() => { r.Logger.Info("msg"); });
            Assert.DoesNotThrow(() => { r.Logger.Warn(o, e); });
            Assert.DoesNotThrow(() => { r.Logger.Warn("msg", e); });
            Assert.DoesNotThrow(() => { r.Logger.Warn("msg"); });
            Assert.DoesNotThrow(() => { r.Logger.Error(o, e); });
            Assert.DoesNotThrow(() => { r.Logger.Error("msg", e); });
            Assert.DoesNotThrow(() => { r.Logger.Error("msg"); });
            Assert.DoesNotThrow(() => { r.Logger.Debug(o, e); });
            Assert.DoesNotThrow(() => { r.Logger.Debug("msg", e); });
            Assert.DoesNotThrow(() => { r.Logger.Debug("msg"); });
            Assert.DoesNotThrow(() => { r.Logger.Fatal(o, e); });
            Assert.DoesNotThrow(() => { r.Logger.Fatal("msg", e); });
            Assert.DoesNotThrow(() => { r.Logger.Fatal("msg"); });
            Assert.DoesNotThrow(() => { r.Logger.Exception(o, e); });
            Assert.DoesNotThrow(() => { r.Logger.Exception("msg", e); });
            Assert.DoesNotThrow(() => { r.Logger.Exception("msg"); });
            Assert.DoesNotThrow(() => { r.Logger.TearDown(); });
        }
예제 #3
0
        public void TestSetTestDataProvider()
        {
            var r = ReporterFactory.Build(new MockTestDataProvider());

            Assert.IsInstanceOf(typeof(MockTestDataProvider), r.TestDataProvider);
            r.SetTestDataProvider(new MockTestDataProviderWithException());
            Assert.IsInstanceOf(typeof(MockTestDataProviderWithException), r.TestDataProvider);
        }
예제 #4
0
 public static void Initialize(ReporterSettings settings, ITestDataProvider testDataProvider, string projectName = "")
 {
     lock (Lock)
     {
         if (_initialized)
         {
             return;
         }
         _reporter    = ReporterFactory.Build(settings, testDataProvider, projectName);
         _initialized = true;
     }
 }
예제 #5
0
 public static void Initialize(TestingFramework framework, ITestDataProvider testDataProvider, string projectName = "")
 {
     lock (Lock)
     {
         if (_initialized)
         {
             return;
         }
         _reporter    = ReporterFactory.Build(framework, testDataProvider, projectName);
         _initialized = true;
     }
 }
예제 #6
0
 public static void Initialize(ITestDataProvider testDataProvider)
 {
     lock (Lock)
     {
         if (_initialized)
         {
             return;
         }
         _reporter    = ReporterFactory.Build(testDataProvider);
         _initialized = true;
     }
 }
예제 #7
0
        public void CanCreateWithSettings()
        {
            var s = new ReporterSettings
            {
                DefaultSettings = new ProjectSettings
                {
                    RunGuid            = Guid.NewGuid().ToString(),
                    DataServiceFile    = "Ghpr.LocalFileSystem.dll",
                    LoggerFile         = "",
                    OutputPath         = @"\\server\folder",
                    ProjectName        = "cool project",
                    RealTimeGeneration = true,
                    ReportName         = "report name",
                    Retention          = new RetentionSettings
                    {
                        Amount = 3,
                        Till   = DateTime.Now
                    },
                    RunName       = "run name",
                    RunsToDisplay = 7
                }
            };
            var r = ReporterFactory.Build(s, _provider);

            Assert.NotNull(r.ReporterSettings);
            Assert.NotNull(r.Action);
            Assert.NotNull(r.DataReaderService);
            Assert.NotNull(r.DataWriterService);
            Assert.NotNull(r.TestDataProvider);
            Assert.NotNull(r.Logger);
            Assert.IsInstanceOf(typeof(EmptyLogger), r.Logger);
            Assert.IsInstanceOf(typeof(MockTestDataProvider), r.TestDataProvider);
            Assert.IsInstanceOf(typeof(FileSystemDataReaderService), r.DataReaderService.GetDataReader());
            Assert.IsInstanceOf(typeof(FileSystemDataWriterService), r.DataWriterService.GetDataWriter());
            Assert.AreEqual(s.DefaultSettings.ProjectName, r.ReporterSettings.ProjectName);
            Assert.AreEqual(s.DefaultSettings.ReportName, r.ReporterSettings.ReportName);
            Assert.AreEqual(s.DefaultSettings.RunGuid, r.ReporterSettings.RunGuid);
            Assert.AreEqual(s.DefaultSettings.DataServiceFile, r.ReporterSettings.DataServiceFile);
            Assert.AreEqual(s.DefaultSettings.LoggerFile, r.ReporterSettings.LoggerFile);
            Assert.AreEqual(s.DefaultSettings.OutputPath, r.ReporterSettings.OutputPath);
            Assert.AreEqual(s.DefaultSettings.RealTimeGeneration, r.ReporterSettings.RealTimeGeneration);
            Assert.AreEqual(s.DefaultSettings.Retention.Till, r.ReporterSettings.Retention.Till);
            Assert.AreEqual(s.DefaultSettings.Retention.Amount, r.ReporterSettings.Retention.Amount);
            Assert.AreEqual(s.DefaultSettings.RunName, r.ReporterSettings.RunName);
            Assert.AreEqual(s.DefaultSettings.RunsToDisplay, r.ReporterSettings.RunsToDisplay);
            Assert.AreEqual(s.DefaultSettings.OutputPath, r.ReporterSettings.OutputPath);
            Assert.AreEqual(s.DefaultSettings.RunsToDisplay, r.ReportSettings.RunsToDisplay);
            Assert.AreEqual(s.DefaultSettings.TestsToDisplay, r.ReportSettings.TestsToDisplay);
            Assert.AreEqual(s.DefaultSettings.ProjectName, r.ReportSettings.ProjectName);
            Assert.AreEqual(s.DefaultSettings.ReportName, r.ReportSettings.ReportName);
        }
예제 #8
0
 public static void CreateReportFromFile(string path)
 {
     try
     {
         var reporter = ReporterFactory.Build(TestingFramework.NUnit, new TestDataProvider());
         var testRuns = GetTestRunsListFromFile(path);
         reporter.GenerateFullReport(testRuns);
     }
     catch (Exception ex)
     {
         var log = new Core.Utils.Log(GhprEventListener.OutputPath);
         log.Exception(ex, "Exception in CreateReportFromFile");
     }
 }
예제 #9
0
        public static void CreateReportFromFile(string path, ITestDataProvider dataProvider)
        {
            var reporter = ReporterFactory.Build(TestingFramework.MSTest, dataProvider);

            try
            {
                var testRuns = GetTestRunsListFromFile(path);
                reporter.GenerateFullReport(testRuns);
                reporter.CleanUpJob();
                reporter.TearDown();
            }
            catch (Exception ex)
            {
                reporter.Logger.Exception("Exception in CreateReportFromFile", ex);
            }
        }
예제 #10
0
        public void CanCreate()
        {
            var r = ReporterFactory.Build(_provider);

            Assert.NotNull(r.ReporterSettings);
            Assert.NotNull(r.Action);
            Assert.NotNull(r.DataReaderService);
            Assert.NotNull(r.DataWriterService);
            Assert.NotNull(r.TestDataProvider);
            Assert.NotNull(r.Logger);
            Assert.IsInstanceOf(typeof(EmptyLogger), r.Logger);
            Assert.IsInstanceOf(typeof(MockTestDataProvider), r.TestDataProvider);
            Assert.AreEqual("C:\\_GHPReporter_Core_Report", r.ReporterSettings.OutputPath);
            Assert.AreEqual(r.ReporterSettings.RunsToDisplay, r.ReportSettings.RunsToDisplay);
            Assert.AreEqual(r.ReporterSettings.TestsToDisplay, r.ReportSettings.TestsToDisplay);
            Assert.AreEqual(r.ReporterSettings.ProjectName, r.ReportSettings.ProjectName);
            Assert.AreEqual(r.ReporterSettings.ReportName, r.ReportSettings.ReportName);
        }
예제 #11
0
        public void TestReportProcess()
        {
            var r = ReporterFactory.Build(new MockTestDataProvider());

            Assert.IsFalse(r.TestRunStarted);
            r.RunStarted();
            Assert.IsTrue(r.TestRunStarted);
            Assert.AreEqual(0, r.RunRepository.CurrentRun.TestsInfo.Count);
            Assert.AreEqual(0, r.RunRepository.CurrentRun.RunSummary.Total);
            Assert.AreEqual("", r.RunRepository.CurrentRun.Name);
            r.SetRunName("new name");
            Assert.AreEqual("new name", r.RunRepository.CurrentRun.Name);
            r.TestStarted(new TestRunDto());
            r.TestFinished(new TestRunDto(), new TestOutputDto());
            r.AddCompleteTestRun(new TestRunDto(), new TestOutputDto());
            r.RunFinished();
            r.TearDown();
        }
예제 #12
0
        public void CanCreateByFramework(TestingFramework framework, string outputPath)
        {
            var r = ReporterFactory.Build(framework, _provider);

            Assert.NotNull(r.ReporterSettings);
            Assert.NotNull(r.Action);
            Assert.NotNull(r.DataReaderService);
            Assert.NotNull(r.DataWriterService);
            Assert.NotNull(r.TestDataProvider);
            Assert.NotNull(r.Logger);
            Assert.IsInstanceOf(typeof(EmptyLogger), r.Logger);
            Assert.IsInstanceOf(typeof(MockTestDataProvider), r.TestDataProvider);
            Assert.AreEqual(outputPath, r.ReporterSettings.OutputPath);
            Assert.AreEqual(r.ReporterSettings.RunsToDisplay, r.ReportSettings.RunsToDisplay);
            Assert.AreEqual(r.ReporterSettings.TestsToDisplay, r.ReportSettings.TestsToDisplay);
            Assert.AreEqual(r.ReporterSettings.ProjectName, r.ReportSettings.ProjectName);
            Assert.AreEqual(r.ReporterSettings.ReportName, r.ReportSettings.ReportName);
        }
예제 #13
0
        public static void CreateReportFromFile(string path)
        {
            IReporter reporter = null;

            try
            {
                reporter = ReporterFactory.Build(TestingFramework.NUnit, new TestDataProvider());
                var testRuns = GetTestRunsListFromFile(path, reporter.Logger);
                foreach (var ghprTestCase in testRuns.Where(t => t.GhprTestScreenshots.Any()))
                {
                    foreach (var screenshot in ghprTestCase.GhprTestScreenshots)
                    {
                        reporter.DataService.SaveScreenshot(screenshot);
                    }
                }
                reporter.GenerateFullReport(testRuns.Select(tr => new KeyValuePair <TestRunDto, TestOutputDto>(tr.GhprTestRun, tr.GhprTestOutput)).ToList());
                reporter.TearDown();
            }
            catch (Exception ex)
            {
                reporter?.Logger.Exception("Exception in CreateReportFromFile", ex);
            }
        }
예제 #14
0
 static GhprEventListener()
 {
     Reporter = ReporterFactory.Build(TestingFramework.NUnit, new TestDataProvider());
 }
        public void OnTestEvent(string report)
        {
            var eventTime = DateTime.UtcNow;
            var xmlNode   = XmlHelper.CreateXmlNode(report);

            switch (xmlNode.Name)
            {
            case "start-run":
            {
                var cmd      = Environment.CommandLine;
                var args     = Environment.GetCommandLineArgs();
                var projName = args.Length >= 2 ? args[1] : cmd;
                Reporter = ReporterFactory.Build(TestingFramework.NUnit, new TestDataProvider(), projName);
                Reporter.RunStarted();
                _testCases  = new List <GhprTestCase>();
                _testSuites = new List <GhprTestSuite>();
                break;
            }

            case "start-test":
            {
                var testRun = TestRunHelper.GetTestRunOnStarted(xmlNode, eventTime, Reporter.Logger);
                Reporter.TestStarted(testRun.GhprTestRun);
                break;
            }

            case "test-case":
            {
                var testCase = TestRunHelper.GetTestRunOnFinished(xmlNode, eventTime, Reporter.Logger);
                testCase.GhprTestOutput.TestOutputInfo.Date = eventTime;
                foreach (var screenshot in testCase.GhprTestScreenshots)
                {
                    var testScreenshotInfo = Reporter.DataWriterService.SaveScreenshot(screenshot);
                    if (testCase.GhprTestRun.Screenshots.All(s => s.Date != screenshot.TestScreenshotInfo.Date))
                    {
                        testCase.GhprTestRun.Screenshots.Add(testScreenshotInfo);
                    }
                }
                Reporter.TestFinished(testCase.GhprTestRun, testCase.GhprTestOutput);
                _testCases.Add(testCase);
                break;
            }

            case "test-suite":
            {
                var testSuite = TestRunHelper.GetTestSuite(xmlNode);
                _testSuites.Add(testSuite);
                var tests = _testCases.Where(tc => tc.ParentId.Equals(testSuite.Id) && !tc.ParentId.Equals(""))
                            .ToList();
                var childSuites = _testSuites
                                  .Where(ts => ts.ParentId.Equals(testSuite.Id) && !ts.ParentId.Equals("") && ts.Type.Equals("ParameterizedFixture")).ToList();
                foreach (var suite in childSuites)
                {
                    tests.AddRange(_testCases.Where(tc => tc.ParentId.Equals(suite.Id) && !tc.ParentId.Equals("")));
                }
                foreach (var test in tests)
                {
                    test.GhprTestOutput.SuiteOutput = testSuite.Output;
                    Reporter.DataWriterService.UpdateTestOutput(test.GhprTestRun.TestInfo, test.GhprTestOutput);
                }

                break;
            }

            case "test-run":
            {
                Reporter.RunFinished();
                Reporter.CleanUpJob();
                Reporter.TearDown();
                break;
            }
            }
        }
예제 #16
0
        public static void Main(string[] args)
        {
            var reporter = ReporterFactory.Build(new DummyTestDataProvider());

            ResourceExtractor.ExtractReportBase(reporter.ReporterSettings.OutputPath);

            reporter.Logger.Info("STARTED");

            var reportSettings = new ReportSettingsDto(5, 7, "Awesome report", "Awesome project");

            reporter.DataWriterService.SaveReportSettings(reportSettings);
            reporter.DataWriterService.SaveReportSettings(reportSettings);
            reporter.DataWriterService.SaveReportSettings(reportSettings);

            var run = new RunDto
            {
                RunInfo = new ItemInfoDto
                {
                    Start  = DateTime.Now.AddMinutes(-2),
                    Finish = DateTime.Now,
                    Guid   = Guid.NewGuid()
                },
                RunSummary = new RunSummaryDto(),
                Name       = "Awesome run",
                Sprint     = "Sprint 1",
                TestsInfo  = new List <ItemInfoDto>()
            };

            reporter.DataWriterService.SaveRun(run);
            reporter.DataWriterService.SaveRun(run);

            reporter.Logger.Info("RUN SAVED");

            var testGuid = Guid.NewGuid();
            var screen   = new TestScreenshotDto
            {
                TestScreenshotInfo = new SimpleItemInfoDto
                {
                    Date     = DateTime.Now,
                    ItemName = "Screenshot"
                },
                Base64Data = "ASDJasdkajasdfas==",
                TestGuid   = testGuid
            };
            var test     = new TestRunDto(testGuid, "Test", "Test.FullName");
            var testInfo = new ItemInfoDto
            {
                Start  = DateTime.Now.AddSeconds(-2),
                Finish = DateTime.Now.AddSeconds(2),
                Guid   = testGuid
            };

            test.TestInfo = testInfo;
            reporter.DataWriterService.SaveScreenshot(screen);
            reporter.DataWriterService.SaveTestRun(test, new TestOutputDto
            {
                TestOutputInfo = new SimpleItemInfoDto
                {
                    Date     = DateTime.Now,
                    ItemName = "Some output"
                },
                Output      = "output",
                SuiteOutput = "suite output"
            });

            reporter.Logger.Info("DONE");
            reporter.TearDown();
        }
예제 #17
0
 static GhprTestAttribute()
 {
     Reporter = ReporterFactory.Build(TestingFramework.NUnit, new TestDataProvider());
 }
예제 #18
0
 static GhprTestAttribute()
 {
     Reporter = ReporterFactory.Build(TestingFramework.NUnit, new TestDataProvider());
     StaticLog.Initialize(Reporter.ReporterSettings.OutputPath);
 }