Example #1
0
        public void ExecuteAssemblies(
            [UsingFactories("AssemblyNames")] string name,
            [UsingFactories("AssemblyNames")] string secondName,
            [UsingFactories("AssemblyNames")] string thirdName
            )
        {
            int       successCount = 0;
            ArrayList names        = new ArrayList();

            names.Add(name);
            names.Add(secondName);
            names.Add(thirdName);

            if (names.Contains("ChildAssembly"))
            {
                if (!names.Contains("SickParentAssembly"))
                {
                    successCount++;
                }
            }
            if (names.Contains("ParentAssembly"))
            {
                successCount++;
            }

            string[] files = new string[] { name + ".dll", secondName + ".dll", thirdName + ".dll" };

            using (TestDomainDependencyGraph graph = TestDomainDependencyGraph.BuildGraph(files, null, MbUnit.Core.Filters.FixtureFilters.Any, false))
            {
                ReportResult result = graph.RunTests();
                Assert.AreEqual(successCount, result.Counter.SuccessCount);
            }
        }
Example #2
0
        private bool InternalExecute()
        {
            this.Log.LogMessage("MbUnit {0} test runner",
                                typeof(Fixture).Assembly.GetName().Version);

            this.DisplayTaskConfiguration();
            // check data
            this.VerifyData();

            // create new report
            this.result = new ReportResult();

            // load and execute
            using (
                TestDomainDependencyGraph graph =
                    TestDomainDependencyGraph.BuildGraph(this.Assemblies, this.AssemblyPaths, FixtureFilters.Any, false))
            {
                graph.Log += new ErrorReporter(graph_Log);
                ReportResult r = graph.RunTests();
                graph.Log -= new ErrorReporter(graph_Log);
                result.Merge(r);
            }

            this.GenerateReports();

            return(result.Counter.FailureCount == 0);
        }
Example #3
0
        public int Main()
        {
            consoleOut.WriteLine("Start time: {0}", DateTime.Now.ToShortTimeString());
            // add path
            foreach (string assemblyPath in this.Arguments.AssemblyPath)
            {
                this.resolver.AddHintDirectory(assemblyPath);
            }

            // store real console
            listener.Writer = Console.Out;
            timer.Start();
            try
            {
                ReportResult   result = new ReportResult();
                IFixtureFilter filter = arguments.GetFilter();

                if (this.Arguments.Files.Length == 0)
                {
                    consoleOut.WriteLine("[warning] No test assemblies to execute");
                }
                else
                {
                    consoleOut.WriteLine("[info] Loading test assemblies");
                    using (
                        TestDomainDependencyGraph graph =
                            TestDomainDependencyGraph.BuildGraph(
                                this.Arguments.Files,
                                this.Arguments.AssemblyPath,
                                filter, this.Arguments.Verbose))
                    {
                        //define an assembly resolver routine in case the CLR cannot find our assemblies.
                        AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(AssemblyResolveHandler);


                        graph.Log += new ErrorReporter(graph_Log);
                        consoleOut.WriteLine("[info] Starting execution");
                        ReportResult r = graph.RunTests();
                        graph.Log -= new ErrorReporter(graph_Log);
                        result.Merge(r);
                    }
                }

                this.GenerateReport(arguments, result);
                timer.Stop();
                consoleOut.WriteLine("[info] MbUnit execution finished in {0}s.", timer.Duration);
                return((0 == result.Counter.FailureCount) ? 0 : -1);
            }
            catch (System.Runtime.Remoting.RemotingException remote)
            {
                consoleOut.WriteLine("Could not load test domain.  Please ensure you have referenced the installed version of MbUnit.Framework within your test assembly. \r\n The error message was: \r\n" + remote.Message);
                return(-3);
            }
            catch (Exception ex)
            {
                consoleOut.WriteLine(ex.ToString());
                return(-3);
            }
        }
Example #4
0
        private bool ExecuteTests(FileSet assemblySet)
        {
            if (assemblySet.FileNames.Count == 0)
            {
                this.Log(Level.Warning, "No tests in assembly set");
                return(true);
            }
            // execute
            string[] assemblieNames = new string[assemblySet.FileNames.Count];
            assemblySet.FileNames.CopyTo(assemblieNames, 0);

            // display information
            this.Log(Level.Info, "Loading {0} assemblies", assemblySet.FileNames.Count);
            foreach (string an in assemblieNames)
            {
                this.Log(Level.Info, "\tAssemblyName: {0}", an);
            }

            string[] dirNames = null;
            if (this.AssemblyPaths != null)
            {
                dirNames = new string[this.AssemblyPaths.DirectoryNames.Count];
                this.AssemblyPaths.DirectoryNames.CopyTo(dirNames, 0);
            }
            try
            {
                using (
                    TestDomainDependencyGraph graph =
                        TestDomainDependencyGraph.BuildGraph(assemblieNames, dirNames, FixtureFilters.Any, false))
                {
                    graph.Log += new MbUnit.Core.Cons.CommandLine.ErrorReporter(graph_Log);
                    try
                    {
                        ReportResult r = graph.RunTests();
                        this.Log(Level.Info, "Finished running tests");
                        this.Log(Level.Info, "Merging results");
                        result.Merge(r);

                        return(r.Counter.FailureCount == 0);
                    }
                    finally
                    {
                        graph.Log -= new MbUnit.Core.Cons.CommandLine.ErrorReporter(graph_Log);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new BuildException("Unexpected engine error while running Tests", ex);
            }
        }
Example #5
0
        bool RunTestAssembly(string fileName, ReportResult reportResult)
        {
            Ensure.ArgumentIsNotNullOrEmptyString(fileName, "fileName");

            string[] assemblyNames = new[] { fileName };
            string[] dirNames      = null;
            if (AssemblyPaths != null)
            {
                dirNames = new string[AssemblyPaths.DirectoryNames.Count];
                AssemblyPaths.DirectoryNames.CopyTo(dirNames, 0);
            }

            try
            {
                Log(Level.Info, "Loading assembly {0}", fileName);
                using (
                    TestDomainDependencyGraph graph = TestDomainDependencyGraph.BuildGraph(assemblyNames,
                                                                                           dirNames,
                                                                                           CreateFilter(),
                                                                                           Verbose))
                {
                    graph.Log += TestRunInfo_Log;
                    string originalWorkingDirectory = Environment.CurrentDirectory;

                    try
                    {
                        Environment.CurrentDirectory = WorkingDirectory.FullName;

                        ReportResult runResult = graph.RunTests();
                        Log(Level.Info, "Finished running tests");

                        Log(Level.Info, "Merging results");
                        reportResult.Merge(runResult);

                        UpdateNAntProperties(Properties, runResult);

                        return(runResult.Counter.FailureCount == 0);
                    }
                    finally
                    {
                        Environment.CurrentDirectory = originalWorkingDirectory;
                        graph.Log -= TestRunInfo_Log;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new BuildException("Unexpected error while running tests", ex);
            }
        }
Example #6
0
        public void ExecuteAssemblies(
            [UsingFactories("AssemblyNames")] string name,
            [UsingFactories("AssemblyNames")] string secondName
            )
        {
            int       successCount = 0;
            ArrayList names        = new ArrayList();

            names.Add(Path.GetFileNameWithoutExtension(name));
            names.Add(Path.GetFileNameWithoutExtension(secondName));

            if (names.Contains("SickParentAssembly"))
            {
                if (names.Contains("ParentAssembly"))
                {
                    successCount++;
                }
            }
            else
            {
                if (names.Contains("ChildAssembly"))
                {
                    successCount++;
                }

                if (names.Contains("ParentAssembly"))
                {
                    successCount++;
                }
            }
            string[] files = new string[] { name, secondName };

            using (TestDomainDependencyGraph graph = TestDomainDependencyGraph.BuildGraph(files, null, MbUnit.Core.Filters.FixtureFilters.Any, true))
            {
                ReportResult result = graph.RunTests();
                Assert.AreEqual(successCount, result.Counter.SuccessCount);
            }
        }