Ejemplo n.º 1
0
        public void AddedAssemblyIsPartOfAssemblyList()
        {
            XunitProject project = new XunitProject();
            XunitProjectAssembly assembly = new XunitProjectAssembly();

            project.AddAssembly(assembly);

            Assert.Contains(assembly, project.Assemblies);
        }
Ejemplo n.º 2
0
        public void ProjectIsDirtyWhenAddingAssembly()
        {
            XunitProject project = new XunitProject();
            XunitProjectAssembly assembly = new XunitProjectAssembly();

            project.AddAssembly(assembly);

            Assert.True(project.IsDirty);
        }
Ejemplo n.º 3
0
        public void ProjectIsDirtyWhenRemovingAssembly()
        {
            XunitProject project = new XunitProject();
            XunitProjectAssembly assembly = new XunitProjectAssembly();
            project.AddAssembly(assembly);
            project.IsDirty = false;

            project.RemoveAssembly(assembly);

            Assert.True(project.IsDirty);
        }
Ejemplo n.º 4
0
        // ReSharper disable PossibleMultipleEnumeration
        /// <summary>
        /// Executes the specified input streams.
        /// </summary>
        /// <param name="inputStreams">The input streams.</param>
        /// <returns>IEnumerable&lt;PvcStream&gt;.</returns>
        public override IEnumerable<PvcStream> Execute(IEnumerable<PvcStream> inputStreams)
        {
            var unit = new XunitProject();

            foreach (var testAssembly in inputStreams.Select(x => x.OriginalSourcePath).Where(File.Exists))
            {
                unit.AddAssembly(new XunitProjectAssembly { AssemblyFilename = testAssembly, ShadowCopy = true });
            }

            unit.RunTestProject(_displaySuccess, _displayFailureStack);

            return inputStreams;
        }
Ejemplo n.º 5
0
        public void ProjectIsMarkedCleanWhenSaved()
        {
            using (TempFile tempFile = new TempFile())
            {
                XunitProject project = new XunitProject();
                XunitProjectAssembly assembly = new XunitProjectAssembly { AssemblyFilename = @"C:\FooBar" };
                project.AddAssembly(assembly);

                project.SaveAs(tempFile.Filename);

                Assert.False(project.IsDirty);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Loads an xUnit.net Test Project file from disk.
        /// </summary>
        /// <param name="filename">The test project filename</param>
        public static XunitProject Load(string filename)
        {
            filename = Path.GetFullPath(filename);
            string directory = Path.GetDirectoryName(filename);
            XmlDocument doc = new XmlDocument();
            XunitProject result = new XunitProject { Filename = filename };

            try
            {
                doc.Load(filename);
            }
            catch (XmlException)
            {
                throw new ArgumentException("The xUnit.net project file appears to be malformed.", "filename");
            }

            foreach (XmlNode assemblyNode in doc.SelectNodes("xunit/assemblies/assembly"))
            {
                XunitProjectAssembly assembly = new XunitProjectAssembly
                {
                    AssemblyFilename = Path.GetFullPath(Path.Combine(directory, assemblyNode.Attributes["filename"].Value))
                };

                if (assemblyNode.Attributes["config-filename"] != null)
                    assembly.ConfigFilename = Path.GetFullPath(Path.Combine(directory, assemblyNode.Attributes["config-filename"].Value));
                if (assemblyNode.Attributes["shadow-copy"] != null)
                    assembly.ShadowCopy = Boolean.Parse(assemblyNode.Attributes["shadow-copy"].Value);

                foreach (XmlNode outputNode in assemblyNode.SelectNodes("output"))
                    assembly.Output.Add(outputNode.Attributes["type"].Value,
                                        Path.GetFullPath(Path.Combine(directory, outputNode.Attributes["filename"].Value)));

                result.assemblies.Add(assembly);
            }

            if (result.assemblies.Count == 0)
                throw new ArgumentException("The xUnit.net project file has no assemblies.", "filename");

            return result;
        }
Ejemplo n.º 7
0
        public void InvalidFilenameThrows()
        {
            XunitProject project = new XunitProject { Filename = @"C:\\" + Guid.NewGuid() + "\\" + Guid.NewGuid() };
            project.AddAssembly(new XunitProjectAssembly { AssemblyFilename = "foo" });

            Assert.Throws<DirectoryNotFoundException>(() => project.Save());
        }
Ejemplo n.º 8
0
        public void FilenamesAreRelativeToTheProjectLocation()
        {
            string expectedXml = @"<?xml version=""1.0"" encoding=""utf-8""?>
            <xunit>
              <assemblies>
            <assembly filename=""C:\AssemblyFilename"" config-filename=""ConfigFilename"" shadow-copy=""true"" />
              </assemblies>
            </xunit>";

            using (TempFile tempFile = new TempFile())
            {
                string directory = Path.GetDirectoryName(tempFile.Filename);
                XunitProject project = new XunitProject { Filename = tempFile.Filename };
                project.AddAssembly(
                    new XunitProjectAssembly
                    {
                        AssemblyFilename = @"C:\AssemblyFilename",
                        ConfigFilename = Path.Combine(directory, "ConfigFilename")
                    });

                project.Save();

                Assert.Equal(expectedXml, File.ReadAllText(tempFile.Filename));
            }
        }
Ejemplo n.º 9
0
 public void EmptyProjectThrows()
 {
     using (TempFile tempFile = new TempFile())
     {
         XunitProject project = new XunitProject { Filename = tempFile.Filename };
         Assert.Throws<InvalidOperationException>(() => project.Save());
     }
 }
Ejemplo n.º 10
0
        public void NullFilenameThrows()
        {
            XunitProject project = new XunitProject();
            project.AddAssembly(new XunitProjectAssembly { AssemblyFilename = "foo" });

            Assert.Throws<ArgumentNullException>(() => project.SaveAs(null));
        }
Ejemplo n.º 11
0
        static int RunProject(XunitProject project, bool teamcity, bool silent, ParallelXunitCommandLine parallelXunitCommandLine)
        {
            if (!parallelXunitCommandLine.Start.HasValue || !parallelXunitCommandLine.End.HasValue)
                return -1;

            int totalAssemblies = 0;
            int totalTests = 0;
            int totalFailures = 0;
            int totalSkips = 0;
            double totalTime = 0;

            var mate = new MultiAssemblyTestEnvironment();

            foreach (XunitProjectAssembly assembly in project.Assemblies)
            {
                parallelXunitCommandLine.SetOutputArguments(assembly.Output);

                TestAssembly testAssembly = mate.Load(assembly.AssemblyFilename, assembly.ConfigFilename, assembly.ShadowCopy);
                List<IResultXmlTransform> transforms = TransformFactory.GetAssemblyTransforms(assembly);

                try
                {
                    var start = parallelXunitCommandLine.Start.Value;
                    var end = parallelXunitCommandLine.End.Value;
                    var methods = new List<TestMethod>(testAssembly.EnumerateTestMethods(project.Filters.Filter)).Skip(start).Take(end - start).ToList();
                    if (methods.Count == 0)
                    {
                        Console.WriteLine("Skipping assembly (no tests match the specified filter).");
                        continue;
                    }

                    var callback = CreateCallback(teamcity, silent, methods.Count);
                    var assemblyXml = testAssembly.Run(methods, callback);

                    ++totalAssemblies;
                    totalTests += callback.TotalTests;
                    totalFailures += callback.TotalFailures;
                    totalSkips += callback.TotalSkips;
                    totalTime += callback.TotalTime;

                    ParallelXunitCommandLine.WriteResultFile(assembly.AssemblyFilename, totalTests, totalFailures, totalSkips, totalTime, start, end);

                    foreach (var transform in transforms)
                        transform.Transform(assemblyXml);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }

                mate.Unload(testAssembly);
            }

            if (!teamcity && totalAssemblies > 1)
            {
                Console.WriteLine();
                Console.WriteLine("=== {0} total, {1} failed, {2} skipped, took {3} seconds ===",
                                   totalTests, totalFailures, totalSkips, totalTime.ToString("0.000", CultureInfo.InvariantCulture));
            }

            return totalFailures;
        }
Ejemplo n.º 12
0
        static int RunProject(XunitProject project, bool teamcity, bool silent, string[] args)
        {
            var defaultArgs = args.Aggregate((a, b) => a + " " + b);

            var mate = new MultiAssemblyTestEnvironment();
            foreach (XunitProjectAssembly assembly in project.Assemblies)
            {
                TestAssembly testAssembly = mate.Load(assembly.AssemblyFilename, assembly.ConfigFilename, assembly.ShadowCopy);
                var methods = new List<TestMethod>(testAssembly.EnumerateTestMethods(project.Filters.Filter));
                var methodsCount = methods.Count;

                ParallelXunitCommandLine.DeleteResultFiles(assembly.AssemblyFilename);

                using (var waiter = new ProcessWaiter())
                {
                    waiter.DefaultArgs = defaultArgs;
                    waiter.TeamCity = teamcity;
                    waiter.Silent = silent;

                    Console.WriteLine("Running with {0} threads.", waiter.MaximumNumberOfProcesses);
                    Console.WriteLine("Total number of tests: {0}.", methodsCount);

                    IParallelTestMethodRunnerCallback callback = CreateCallback(teamcity, silent, methodsCount);
                    callback.ParentAssemblyStart(testAssembly);

                    TestBatch batch;
                    var batcher = new TestMethodBatcher(methodsCount);
                    while ((batch = batcher.GetNextBatch()).Size > 0)
                    {
                        waiter.StartProcess(batch);
                    }

                    if (!teamcity)
                    {
                        waiter.PrintSummary();
                    }
                    else
                    {
                        waiter.WaitForAllProcesses();
                    }

                    var testResult = ParallelXunitCommandLine.AggregateTestResults(assembly.AssemblyFilename);
                    callback.ParentAssemblyFinished(testAssembly, testResult.Total, testResult.Failed, testResult.Skiped);

                    mate.Unload(testAssembly);
                }
            }

            return 0;
        }
Ejemplo n.º 13
0
        public IEnumerable<AutoTest.TestRunners.Shared.Results.TestResult> Run(RunSettings settings)
        {
            var logger = new XUnitLogger();
            XunitProject project = new XunitProject();

            var runner = settings.Assembly;
            // Set assembly externally as XUnit screws up the casing
            logger.SetCurrentAssembly(runner.Assembly);

            XunitProjectAssembly assembly = new XunitProjectAssembly
            {
                AssemblyFilename = runner.Assembly,
                ConfigFilename = null,
                ShadowCopy = false
            };
            project.AddAssembly(assembly);

            foreach (XunitProjectAssembly asm in project.Assemblies)
            {
                using (ExecutorWrapper wrapper = new ExecutorWrapper(asm.AssemblyFilename, asm.ConfigFilename, asm.ShadowCopy))
                {
                    try
                    {
                        var xunitRunner = new TestRunner(wrapper, logger);
                        //Run all tests
                        if (runner.Tests.Count() == 0 && runner.Members.Count() == 0 && runner.Namespaces.Count() == 0)
                            xunitRunner.RunAssembly();
                        //Run tests
                        if (runner.Tests.Count() > 0)
                        {
                            foreach (var test in runner.Tests)
                                xunitRunner.RunTest(test.Substring(0, test.LastIndexOf(".")), test.Substring(test.LastIndexOf(".") + 1, test.Length - (test.LastIndexOf(".") + 1)));
                        }
                        //Run members
                        if (runner.Members.Count() > 0)
                        {
                            foreach (var member in runner.Members)
                                xunitRunner.RunClass(member);
                        }
                        //Run namespaces
                        if (runner.Namespaces.Count() > 0)
                        {
                            var loadedAssembly = Assembly.LoadFrom(runner.Assembly);
                            var types = loadedAssembly.GetExportedTypes();
                            loadedAssembly = null;
                            foreach (var ns in runner.Namespaces)
                            {
                                foreach (Type type in types)
                                    if (ns == null || type.Namespace == ns)
                                        xunitRunner.RunClass(type.FullName);
                            }
                        }
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
            return logger.Results;
        }
Ejemplo n.º 14
0
        public void SaveAcceptanceTest()
        {
            string expectedXml = @"<?xml version=""1.0"" encoding=""utf-8""?>" + Environment.NewLine +
                                 @"<xunit2>" + Environment.NewLine +
                                 @"  <assembly filename=""C:\AssemblyFilename"" config-filename=""C:\ConfigFilename"" shadow-copy=""true"" />" + Environment.NewLine +
                                 @"  <assembly filename=""C:\AssemblyFilename2"" config-filename=""C:\ConfigFilename2"" shadow-copy=""false"" />" + Environment.NewLine +
                                 @"  <output type=""xml"" filename=""C:\XmlFilename"" />" + Environment.NewLine +
                                 @"  <output type=""html"" filename=""C:\HtmlFilename"" />" + Environment.NewLine +
                                 @"</xunit2>";

            using (var tempFile = new TempFile())
            {
                var project = new XunitProject { Filename = tempFile.Filename };
                project.Output.Add("xml", @"C:\XmlFilename");
                project.Output.Add("html", @"C:\HtmlFilename");
                project.AddAssembly(new XunitProjectAssembly() { AssemblyFilename = @"C:\AssemblyFilename", ConfigFilename = @"C:\ConfigFilename", ShadowCopy = true });
                project.AddAssembly(new XunitProjectAssembly() { AssemblyFilename = @"C:\AssemblyFilename2", ConfigFilename = @"C:\ConfigFilename2", ShadowCopy = false });

                project.Save();

                Assert.Equal(expectedXml, File.ReadAllText(tempFile.Filename));
            }
        }
Ejemplo n.º 15
0
        public void AssemblyFilenameOnly()
        {
            string expectedXml = @"<?xml version=""1.0"" encoding=""utf-8""?>" + Environment.NewLine +
                                 @"<xunit2>" + Environment.NewLine +
                                 @"  <assembly filename=""C:\AssemblyFilename"" shadow-copy=""true"" />" + Environment.NewLine +
                                 @"</xunit2>";

            using (var tempFile = new TempFile())
            {
                var project = new XunitProject { Filename = tempFile.Filename };
                project.AddAssembly(new XunitProjectAssembly { AssemblyFilename = @"C:\AssemblyFilename" });

                project.Save();

                Assert.Equal(expectedXml, File.ReadAllText(tempFile.Filename));
            }
        }
Ejemplo n.º 16
0
        public void SaveAcceptanceTest()
        {
            string expectedXml = @"<?xml version=""1.0"" encoding=""utf-8""?>
            <xunit>
              <assemblies>
            <assembly filename=""C:\AssemblyFilename"" config-filename=""C:\ConfigFilename"" shadow-copy=""true"">
              <output type=""xml"" filename=""C:\XmlFilename"" />
              <output type=""html"" filename=""C:\HtmlFilename"" />
            </assembly>
            <assembly filename=""C:\AssemblyFilename2"" config-filename=""C:\ConfigFilename2"" shadow-copy=""false"">
              <output type=""xml"" filename=""C:\XmlFilename2"" />
              <output type=""html"" filename=""C:\HtmlFilename2"" />
            </assembly>
              </assemblies>
            </xunit>";

            using (TempFile tempFile = new TempFile())
            {
                XunitProject project = new XunitProject { Filename = tempFile.Filename };
                XunitProjectAssembly assembly1 = new XunitProjectAssembly();
                assembly1.AssemblyFilename = @"C:\AssemblyFilename";
                assembly1.ConfigFilename = @"C:\ConfigFilename";
                assembly1.ShadowCopy = true;
                assembly1.Output.Add("xml", @"C:\XmlFilename");
                assembly1.Output.Add("html", @"C:\HtmlFilename");
                project.AddAssembly(assembly1);
                XunitProjectAssembly assembly2 = new XunitProjectAssembly();
                assembly2.AssemblyFilename = @"C:\AssemblyFilename2";
                assembly2.ConfigFilename = @"C:\ConfigFilename2";
                assembly2.ShadowCopy = false;
                assembly2.Output.Add("xml", @"C:\XmlFilename2");
                assembly2.Output.Add("html", @"C:\HtmlFilename2");
                project.AddAssembly(assembly2);

                project.Save();

                Assert.Equal(expectedXml, File.ReadAllText(tempFile.Filename));
            }
        }
Ejemplo n.º 17
0
        public void FilenameIsUpdated()
        {
            using (TempFile tempFile = new TempFile())
            {
                XunitProject project = new XunitProject();
                XunitProjectAssembly assembly = new XunitProjectAssembly { AssemblyFilename = @"C:\FooBar" };
                project.AddAssembly(assembly);

                project.SaveAs(tempFile.Filename);

                Assert.Equal(tempFile.Filename, project.Filename);
            }
        }
Ejemplo n.º 18
0
        public void RemovesAssemblyFromAssembliesList()
        {
            XunitProject project = new XunitProject();
            XunitProjectAssembly assembly = new XunitProjectAssembly();
            project.AddAssembly(assembly);

            project.RemoveAssembly(assembly);

            Assert.DoesNotContain(assembly, project.Assemblies);
        }
Ejemplo n.º 19
0
        public void NullFilenameThrows()
        {
            XunitProject project = new XunitProject();

            Assert.Throws<ArgumentNullException>(() => project.Filename = null);
        }
Ejemplo n.º 20
0
        public void UnknownAssemblyDoesNotThrow()
        {
            XunitProject project = new XunitProject();
            XunitProjectAssembly assembly = new XunitProjectAssembly();

            Assert.DoesNotThrow(() => project.RemoveAssembly(assembly));
        }
Ejemplo n.º 21
0
        public void NullAssemblyThrows()
        {
            XunitProject project = new XunitProject();

            Assert.Throws<ArgumentNullException>(() => project.AddAssembly(null));
        }
Ejemplo n.º 22
0
        public void AssemblyFilenameOnly()
        {
            string expectedXml = @"<?xml version=""1.0"" encoding=""utf-8""?>
            <xunit>
              <assemblies>
            <assembly filename=""C:\AssemblyFilename"" shadow-copy=""true"" />
              </assemblies>
            </xunit>";

            using (TempFile tempFile = new TempFile())
            {
                XunitProject project = new XunitProject { Filename = tempFile.Filename };
                project.AddAssembly(
                    new XunitProjectAssembly
                    {
                        AssemblyFilename = @"C:\AssemblyFilename"
                    });

                project.Save();

                Assert.Equal(expectedXml, File.ReadAllText(tempFile.Filename));
            }
        }
Ejemplo n.º 23
0
        public void ProjectIsNotDirtyToStart()
        {
            XunitProject project = new XunitProject();

            Assert.False(project.IsDirty);
        }
Ejemplo n.º 24
0
        static int RunProject(XunitProject project, bool teamcity, bool silent, string[] args)
        {
            var defaultArgs = args.Aggregate((a, b) => a + " " + b);

            var mate = new MultiAssemblyTestEnvironment();
            foreach (XunitProjectAssembly assembly in project.Assemblies)
            {
                TestAssembly testAssembly = mate.Load(assembly.AssemblyFilename, assembly.ConfigFilename, assembly.ShadowCopy);
                var methods = new List<TestMethod>(testAssembly.EnumerateTestMethods(project.Filters.Filter));

                var batcher = new TestMethodBatcher(methods.Count);

                var waiter = new ProcessWaiter();
                waiter.DefaultArgs = defaultArgs;
                waiter.TeamCity = teamcity;
                waiter.Silent = silent;

                Console.WriteLine("Running with {0} threads.", waiter.MaximumNumberOfProcesses);
                Console.WriteLine("Total number of tests: {0}.", methods.Count);

                TestBatch batch;
                while ((batch = batcher.GetNextBatch()).Size > 0)
                {
                    waiter.StartProcess(batch);
                }

                waiter.PrintSummary();

                mate.Unload(testAssembly);
            }

            return 0;
        }