Esempio n. 1
0
        public void VerifyReadResultsReturnsDurationAsSumOfAssemblyTimeWhenRunDateNotAvailable()
        {
            SetupMocks();
            //no run-time tag present
            string            xunitResults = c_parallelXunitResults;
            XUnitResultReader reader       = new XUnitResultReader();

            xunitResults     = xunitResults.Replace("run-time", "timer").Replace("run-date", "dater");
            _xUnitResultFile = "BadXUnitResults2.xml";
            File.WriteAllText(_xUnitResultFile, xunitResults);
            TestRunData runData = reader.ReadResults(_ec.Object, _xUnitResultFile, new TestRunContext("Owner", "any cpu", "debug", 1, "", "releaseUri", "releaseEnvironmentUri"));
            DateTime    startDate, completeDate;

            Assert.Equal(40, (int)runData.Results[0].DurationInMs);
            DateTime.TryParse(runData.StartDate, out startDate);
            Assert.NotEqual("2016-06-08T07:12:09.0000000", startDate.ToString("o"));
            DateTime.TryParse(runData.CompleteDate, out completeDate);
            Assert.Equal((completeDate - startDate).TotalMilliseconds, 10850);
        }
Esempio n. 2
0
        public void VerifyReadResultsReturnsDurationAsDiffBetweenMinStartAndMaxCompletedTime()
        {
            SetupMocks();
            string            xunitResults = c_parallelXunitResults;
            XUnitResultReader reader       = new XUnitResultReader();

            _xUnitResultFile = "XUnitResults.xml";
            File.WriteAllText(_xUnitResultFile, xunitResults);
            TestRunData runData = reader.ReadResults(_ec.Object, _xUnitResultFile, new TestRunContext("Owner", "any cpu", "debug", 1, "", "releaseUri", "releaseEnvironmentUri"));

            Assert.Equal(40, (int)runData.Results[0].DurationInMs);
            DateTime startDate, completeDate;

            DateTime.TryParse(runData.StartDate, out startDate);
            Assert.Equal("2016-06-08T07:12:09.0000000", startDate.ToString("o"));
            DateTime.TryParse(runData.CompleteDate, out completeDate);
            Assert.Equal("2016-06-08T07:12:14.4330000", completeDate.ToString("o"));
            Assert.Equal((completeDate - startDate).TotalMilliseconds, 5433);
        }
Esempio n. 3
0
        private TestRunData GetTestRunData()
        {
            var xunitResults = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                               "<assemblies>" +
                               "<assembly>" +
                               "<collection>" +
                               "<test name=\"MyFirstUnitTests.Class1.Test1\" method=\"asdasdf\">" +
                               "</test>" +
                               "</collection>" +
                               "</assembly>" +
                               "</assemblies>";

            _xUnitResultFile = "BareMinimumXUnitResults.xml";
            File.WriteAllText(_xUnitResultFile, xunitResults);
            _xUnitReader = new XUnitResultReader();
            TestRunData runData = _xUnitReader.ReadResults(_ec.Object, _xUnitResultFile,
                                                           new TestRunContext(null, null, null, 0, null, null, null));

            return(runData);
        }
Esempio n. 4
0
        public void ReadResultsDoesNotFailForV1()
        {
            SetupMocks();
            var xunitResults = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                               "<assemblies>" +
                               "<assembly name = \"C:\\Users\\somerandomusername\\Source\\Workspaces\\p1\\ClassLibrary2\\ClassLibrary2\\bin\\Debug\\ClassLibrary2.DLL\">" +
                               "<class name=\"MyFirstUnitTests.Class1\">" +
                               "<test name=\"MyFirstUnitTests.Class1.FailingTest\">" +
                               "</test>" +
                               "</class>" +
                               "</assembly>" +
                               "</assemblies>";

            _xUnitResultFile = "BadXUnitResults.xml";
            File.WriteAllText(_xUnitResultFile, xunitResults);
            XUnitResultReader reader  = new XUnitResultReader();
            TestRunData       runData = reader.ReadResults(_ec.Object, _xUnitResultFile, new TestRunContext(null, null, null, 0, null, null, null));

            Assert.Equal(0, runData.Results.Length);
        }
Esempio n. 5
0
        public void ResultsWithoutMandatoryFieldsAreSkipped()
        {
            SetupMocks();
            var xunitResults = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                               "<assemblies>" +
                               "<assembly>" +
                               "<collection>" +
                               "<test name=\"\">" +
                               "</test>" +
                               "<test>" +
                               "</test>" +
                               "</collection>" +
                               "</assembly>" +
                               "</assemblies>";

            WriteXUnitFile(xunitResults);
            XUnitResultReader reader  = new XUnitResultReader();
            TestRunData       runData = reader.ReadResults(_ec.Object, _xUnitResultFile, new TestRunContext("Owner", "any cpu", "debug", 1, "", "releaseUri", "releaseEnvironmentUri"));

            Assert.NotNull(runData);
            Assert.Equal(0, runData.Results.Length);
        }
Esempio n. 6
0
        public void ReadsResultsReturnsCorrectValuesInDifferentCulture()
        {
            SetupMocks();
            CultureInfo current = CultureInfo.CurrentCulture;

            try
            {
                //German is used, as in this culture decimal seperator is comma & thousand seperator is dot
                CultureInfo.CurrentCulture = new CultureInfo("de-DE");
                var xunitResults = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                                   "<assemblies>" +
                                   "<assembly name=\"C:/Users/somerandomusername/Source/Workspaces/p1/ClassLibrary2/ClassLibrary2/bin/Debug/ClassLibrary2.DLL\" environment=\"64-bit .NET 4.0.30319.42000 [collection-per-class, parallel]\" test-framework=\"xUnit.net 2.0.0.2929\" run-date=\"2015-08-18\" run-time=\"06:17:15\" config-file=\"C:\\Users\\somerandomusername\\Source\\Workspaces\\p1\\ClassLibrary2\\packages\\xunit.runner.console.2.0.0\\tools\\xunit.console.exe.Config\" total=\"2\" passed=\"1\" failed=\"1\" skipped=\"0\" time=\"0.233\" errors=\"0\">" +
                                   "<errors />" +
                                   "<collection total=\"2\" passed=\"1\" failed=\"1\" skipped=\"0\" name=\"Test collection for MyFirstUnitTests.Class1\" time=\"0.044\">" +
                                   "<test name=\"MyFirstUnitTests.Class1.FailingTest\" type=\"MyFirstUnitTests.Class1\" method=\"FailingTest\" time=\"1.0422319\" result=\"Fail\">" +
                                   "<failure exception-type=\"Xunit.Sdk.EqualException\" >" +
                                   "<message><![CDATA[Assert.Equal() Failure" +
                                   "Expected: 5" +
                                   "Actual: 4]]></message >" +
                                   "<stack-trace><![CDATA[at MyFirstUnitTests.Class1.FailingTest() in C: \\Users\\somerandomusername\\Source\\Workspaces\\p1\\ClassLibrary2\\ClassLibrary2\\Class1.cs:line 17]]></stack-trace>" +
                                   "</failure >" +
                                   "<output><![CDATA[This is standard console output for xunit.]]></output>" +
                                   "</test>" +
                                   "<test name=\"MyFirstUnitTests.Class1.PassingTest\" type=\"MyFirstUnitTests.Class1\" method=\"PassingTest\" time=\"0.0014079\" result=\"Pass\">" +
                                   "<traits>" +
                                   "<trait name=\"priority\" value=\"0\" />" +
                                   "<trait name=\"owner\" value=\"asdf\" />" +
                                   "</traits>" +
                                   "</test>" +
                                   "</collection>" +
                                   "</assembly>" +
                                   "<assembly name=\"C:\\Users\\somerandomusername\\Source\\Workspaces\\p1\\ClassLibrary2\\ClassLibrary1\\bin\\Debug\\ClassLibrary1.DLL\" environment=\"64-bit .NET 4.0.30319.42000 [collection-per-class, parallel]\" test-framework=\"xUnit.net 2.0.0.2929\" run-date=\"2015-08-18\" run-time=\"06:17:16\" config-file=\"C:\\Users\\somerandomusername\\Source\\Workspaces\\p1\\ClassLibrary2\\packages\\xunit.runner.console.2.0.0\\tools\\xunit.console.exe.Config\" total=\"2\" passed=\"2\" failed=\"0\" skipped=\"0\" time=\"0.152\" errors=\"0\">" +
                                   "<errors />" +
                                   "<collection total=\"2\" passed=\"2\" failed=\"0\" skipped=\"0\" name=\"Test collection for MyFirstUnitTests.Class2\" time=\"0.006\">" +
                                   "<test name=\"MyFirstUnitTests.Class2.tset2\" type=\"MyFirstUnitTests.Class2\" method=\"tset2\" time=\"0.0056931\" result=\"Pass\" />" +
                                   "<test name=\"MyFirstUnitTests.Class2.test1\" type=\"MyFirstUnitTests.Class2\" method=\"test1\" time=\"0.0001093\" result=\"Pass\">" +
                                   "<traits>" +
                                   "<trait name=\"priority\" value=\"0\" />" +
                                   "</traits>" +
                                   "</test>" +
                                   "</collection>" +
                                   "</assembly>" +
                                   "</assemblies>";
                _xUnitResultFile = "XUnitResults.xml";
                File.WriteAllText(_xUnitResultFile, xunitResults);
                XUnitResultReader reader  = new XUnitResultReader();
                TestRunData       runData = reader.ReadResults(_ec.Object, _xUnitResultFile, new TestRunContext("Owner", "any cpu", "debug", 1, "", "releaseUri", "releaseEnvironmentUri"));
                Assert.Equal("XUnit Test Run debug any cpu", runData.Name);
                Assert.Equal(4, runData.Results.Length);
                Assert.Equal("debug", runData.BuildFlavor);
                Assert.Equal("any cpu", runData.BuildPlatform);
                Assert.Equal("1", runData.Build.Id);
                Assert.Equal(1, runData.Attachments.Length);
                Assert.Equal("Failed", runData.Results[0].Outcome);
                Assert.Equal("FailingTest", runData.Results[0].TestCaseTitle);
                Assert.Equal("MyFirstUnitTests.Class1.FailingTest", runData.Results[0].AutomatedTestName);
                Assert.Equal("Assert.Equal() FailureExpected: 5Actual: 4", runData.Results[0].ErrorMessage);
                Assert.Equal("at MyFirstUnitTests.Class1.FailingTest() in C: \\Users\\somerandomusername\\Source\\Workspaces\\p1\\ClassLibrary2\\ClassLibrary2\\Class1.cs:line 17", runData.Results[0].StackTrace);
                Assert.Equal("This is standard console output for xunit.", runData.Results[0].AttachmentData.ConsoleLog);
                Assert.Equal("Owner", runData.Results[0].RunBy.DisplayName);
                Assert.Equal("Completed", runData.Results[0].State);
                Assert.Equal("1042", runData.Results[0].DurationInMs.ToString());
                Assert.Equal("ClassLibrary2.DLL", runData.Results[0].AutomatedTestStorage);
                Assert.Equal("Passed", runData.Results[1].Outcome);
                Assert.Equal("0", runData.Results[1].Priority.ToString());
                Assert.Equal("asdf", runData.Results[1].Owner.DisplayName);
                Assert.Equal(null, runData.Results[0].AutomatedTestId);
                Assert.Equal(null, runData.Results[0].AutomatedTestTypeId);
                DateTime startDate;
                DateTime.TryParse(runData.StartDate, out startDate);
                DateTime completeDate;
                DateTime.TryParse(runData.CompleteDate, out completeDate);
                Assert.Equal((completeDate - startDate).TotalMilliseconds, 1152);
                Assert.Equal("releaseUri", runData.ReleaseUri);
                Assert.Equal("releaseEnvironmentUri", runData.ReleaseEnvironmentUri);
            }
            finally
            {
                CultureInfo.CurrentCulture = current;
            }
        }