public ReportResult RunTests()
        {
            ReportResult result = new ReportResult();
            if (graph.VerticesCount == 0)
            {
                this.OnLog("No assembly to execute");
                result.UpdateCounts();
                return result;
            }

            this.OnLog("Sorting assemblies by dependencies");
            // create topological sort
            ArrayList sortedVertices = new ArrayList();
            TopologicalSortAlgorithm topo = new TopologicalSortAlgorithm(graph);
            topo.Compute(sortedVertices);
            if (sortedVertices.Count == 0)
                throw new InvalidOperationException("Cannot be zero");

            // set vertices colors
            this.OnLog("etting up fixture colors");
            VertexColorDictionary colors = new VertexColorDictionary();
            foreach (TestDomainVertex v in graph.Vertices)
                colors.Add(v, GraphColor.White);

            // execute each domain
            foreach (TestDomainVertex v in sortedVertices)
            {
                // if vertex color is not white, skip it
                GraphColor color = colors[v];
                if (color != GraphColor.White)
                {
                    this.OnLog("Skipping assembly {0} because dependent assembly failed", v.Domain.TestEngine.Explorer.AssemblyName);
                    // mark children
                    foreach (TestDomainVertex child in graph.AdjacentVertices(v))
                        colors[child] = GraphColor.Black;
                    continue;
                }

                this.OnLog("Loading {0}", v.Domain.TestEngine.Explorer.AssemblyName);

                ReportCounter counter = v.Domain.TestEngine.GetTestCount();
                this.OnLog("Found  {0} tests", counter.RunCount);
                this.OnLog("Running fixtures.");
                v.Domain.TestEngine.RunPipes();
                counter = v.Domain.TestEngine.GetTestCount();
                this.OnLog("Tests finished: {0} tests, {1} success, {2} failures, {3} ignored"
                    , counter.RunCount
                    , counter.SuccessCount
                    , counter.FailureCount
                    , counter.IgnoreCount
                    );

                result.Merge(v.Domain.TestEngine.Report.Result);

                if (counter.FailureCount != 0)
                {
                    // mark children as failed
                    colors[v] = GraphColor.Black;
                    foreach (TestDomainVertex child in graph.AdjacentVertices(v))
                        colors[child] = GraphColor.Black;
                }
                else
                {
                    // mark vertex as succesfull
                    colors[v] = GraphColor.Gray;
                }
            }

            result.UpdateCounts();
            MbUnit.Framework.Assert.IsNotNull(result);
            MbUnit.Framework.Assert.IsNotNull(result.Counter);

            this.OnLog("All Tests finished: {0} tests, {1} success, {2} failures, {3} ignored in {4} seconds"
                , result.Counter.RunCount
                , result.Counter.SuccessCount
                , result.Counter.FailureCount
                , result.Counter.IgnoreCount
                , result.Counter.Duration
                );

            return result;
        }
        public ReportResult GetReport()
        {
            ReportResult result = new ReportResult();
            result.Date = DateTime.Now;

            foreach(TreeTestDomain td in this.list)
            {
                if (td.TestEngine == null)
                    continue;
                if (td.TestEngine.Report == null)
                    continue;
                if (td.TestEngine.Report.Result == null)
                    continue;

                result.Merge(td.TestEngine.Report.Result);
            }

            result.UpdateCounts();
            return result;
        }
Esempio n. 3
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);
			}
		}
Esempio n. 4
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 (Exception ex)
            {
                consoleOut.WriteLine(ex.ToString());
            return -3;
            }
        }
Esempio n. 5
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;
        }