public AutoRunner(Assembly testAssembly) { TypeHelper.InvokeFutureStaticMethod( typeof(System.Windows.Forms.Application), "EnableVisualStyles"); this.resolver = new AssemblyResolverManager(); this.resolver.AddMbUnitDirectories(); this.domain = new AssemblyTestDomain(testAssembly); }
public void Dispose() { if (this.resolver != null) { this.resolver.Dispose(); this.resolver = null; } if (this.Domain != null) { this.Domain.Dispose(); this.domain = null; } }
public void Load() { try { AddLog("MbUnit AutoRunner"); AddLog("Loading test domain"); // load domain this.domain.Load(); } catch (Exception ex) { AddLog("Exception occured while loading"); AddLog(ex.ToString()); if (this.domain != null) { this.domain.Dispose(); this.domain = null; } throw new Exception("Exception while loading assemblies", ex); } }
protected TestRunState Run( ITestListener testListener, Assembly assembly, IFixtureFilter filter, RunPipeFilterBase runPipeFilter, TypeFilterBase typeFilter ) { this.testListener = testListener; if (!CheckMbUnitVersion(assembly)) { return(TestRunState.Error); } assemblySetUpCount = 0; assemblyTearDownCount = 0; testFixtureSetUpCount = 0; testFixtureTearDownCount = 0; failureCount = 0; successCount = 0; ignoreCount = 0; skipCount = 0; string assemblyPath = new Uri(assembly.CodeBase).LocalPath; testListener.WriteLine("Starting the MbUnit Test Execution", Category.Info); testListener.WriteLine("Exploring " + assembly.FullName, Category.Info); testListener.WriteLine(String.Format("MbUnit {0} Addin", typeof(RunPipe).Assembly.GetName().Version), Category.Info); try { using (AssemblyTestDomain domain = new AssemblyTestDomain(assembly)) { //define an assembly resolver routine in case the CLR cannot find our assemblies. AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(AssemblyResolveHandler); domain.TypeFilter = typeFilter; domain.Filter = filter; domain.RunPipeFilter = runPipeFilter; domain.Load(); // check found tests testCount = domain.TestEngine.GetTestCount().RunCount; if (testCount == 0) { testListener.WriteLine("No tests found", Category.Info); return(TestRunState.NoTests); } testListener.WriteLine(String.Format("Found {0} tests", testCount), Category.Info); // add listeners domain.TestEngine.FixtureRunner.AssemblySetUp += new ReportSetUpAndTearDownEventHandler(TestEngine_AssemblySetUp); domain.TestEngine.FixtureRunner.AssemblyTearDown += new ReportSetUpAndTearDownEventHandler(TestEngine_AssemblyTearDown); domain.TestEngine.FixtureRunner.TestFixtureSetUp += new ReportSetUpAndTearDownEventHandler(TestEngine_TestFixtureSetUp); domain.TestEngine.FixtureRunner.TestFixtureTearDown += new ReportSetUpAndTearDownEventHandler(TestEngine_TestFixtureTearDown); domain.TestEngine.FixtureRunner.RunResult += new ReportRunEventHandler(TestEngine_RunResult); try { domain.TestEngine.RunPipes(); } finally { if (domain.TestEngine != null) { domain.TestEngine.FixtureRunner.AssemblySetUp -= new ReportSetUpAndTearDownEventHandler(TestEngine_AssemblySetUp); domain.TestEngine.FixtureRunner.AssemblyTearDown -= new ReportSetUpAndTearDownEventHandler(TestEngine_AssemblyTearDown); domain.TestEngine.FixtureRunner.TestFixtureSetUp -= new ReportSetUpAndTearDownEventHandler(TestEngine_TestFixtureSetUp); domain.TestEngine.FixtureRunner.TestFixtureTearDown -= new ReportSetUpAndTearDownEventHandler(TestEngine_TestFixtureTearDown); domain.TestEngine.FixtureRunner.RunResult -= new ReportRunEventHandler(TestEngine_RunResult); } } testListener.WriteLine("[reports] generating HTML report", Category.Info); this.GenerateReports(testListener, assembly, domain.TestEngine.Report.Result); return(toTestRunState(domain.TestEngine.Report.Result)); } } catch (Exception ex) { testListener.WriteLine("[critical-failure]", Category.Error); testListener.WriteLine(ex.ToString(), Category.Error); throw new Exception("Test execution failed", ex); } }