public NUnit2FrameworkDriver(AppDomain testDomain, string frameworkAssemblyName, string testAssemblyPath, IDictionary <string, object> settings) { if (!File.Exists(testAssemblyPath)) { throw new ArgumentException("testAssemblyPath", "Framework driver constructor called with a file name that doesn't exist."); } _testDomain = testDomain; _testAssemblyPath = testAssemblyPath; _frameworkAssemblyName = frameworkAssemblyName; _name = Escape(Path.GetFileName(_testAssemblyPath)); _fullname = Escape(_testAssemblyPath); var initializer = DomainInitializer.CreateInstance(_testDomain); initializer.InitializeDomain((int)InternalTrace.Level); _runner = RemoteTestRunner.CreateInstance(_testDomain, 1); _package = new Core.TestPackage(_frameworkAssemblyName); foreach (var key in settings.Keys) { _package.Settings[key] = settings[key]; } }
public TestRun(string fileName) { TestPackage testPackage = new TestPackage(fileName); remoteTesRunner = new RemoteTestRunner(); remoteTesRunner.Load(testPackage); }
public static int RunAllTests() { var executingAssembly = Assembly.GetExecutingAssembly(); var assemblyFilename = executingAssembly.Location; var consoleOut = Console.Out; var testPackage = new TestPackage(assemblyFilename) { AutoBinPath = true }; testPackage.Settings["ShadowCopyFiles"] = false; testPackage.Settings["UseThreadedRunner"] = false; var listener = new SledEventListener { ConsoleOut = consoleOut }; var testRunner = new RemoteTestRunner(); testRunner.Load(testPackage); testRunner.Run(listener); if (listener.FailedTestCount == 0) { consoleOut.WriteLine("Success: " + listener.TestCount + " test(s) passed."); } return(listener.FailedTestCount); }
public TestResult Run (EventListener listener, ITestFilter filter, string path, string suiteName, List<string> supportAssemblies, string testRunnerType, string testRunnerAssembly) { InitSupportAssemblies (supportAssemblies); if (filter == null) filter = TestFilter.Empty; TestRunner tr; if (!string.IsNullOrEmpty (testRunnerType)) { Type runnerType; if (string.IsNullOrEmpty (testRunnerAssembly)) runnerType = Type.GetType (testRunnerType, true); else { var asm = Assembly.LoadFrom (testRunnerAssembly); runnerType = asm.GetType (testRunnerType); } tr = (TestRunner)Activator.CreateInstance (runnerType); } else tr = new RemoteTestRunner (); TestPackage package = new TestPackage (path); if (!string.IsNullOrEmpty (suiteName)) package.TestName = suiteName; tr.Load (package); return tr.Run (listener, filter, false, LoggingThreshold.All); }
private void RunTests(IEnumerable <TestDetails> selectedTests) { if (_testRunnerTask == null) { _viewModel.CanRunTests = false; _viewModel.TestsAreRunning = true; SetStatus("Running..."); var testClosure = selectedTests; NotifyUnrunTests(testClosure); _testRunnerTask = new TaskFactory().StartNew(() => { RemoteTestRunner runner = new RemoteTestRunner(_outputWriter); runner.RunTests(testClosure); _testRunnerTask = null; SetStatus("Done"); _viewModel.CanRunTests = true; _viewModel.TestsAreRunning = false; }); } }
public NUnitManagedTestRunner() { _task = new Task(DoTests); _testAssemblyLocation = null; _testsToRun = null; Result = null; _remoteTestRunner = new RemoteTestRunner(); ExitCode = -1; }
/// <summary> /// Create a new NUnit2FrameworkDriver /// </summary> /// <param name="testDomain">The AppDomain to use for the runner</param> /// <remarks> /// The framework assembly name is needed because this driver is used for both the /// nunit.framework 2.x and nunitlite 1.0. /// </remarks> public NUnit2FrameworkDriver(AppDomain testDomain) { _testDomain = testDomain; var initializer = DomainInitializer.CreateInstance(_testDomain); initializer.InitializeDomain((int)InternalTrace.Level); _runner = RemoteTestRunner.CreateInstance(_testDomain, 1); }
static void Main(string[] args) { CoreExtensions.Host.InitializeService(); TestSuiteBuilder builder = new TestSuiteBuilder(); TestPackage testPackage = new TestPackage(@"d:\Programming\RoboFootball\Platform\Arbiter.Test\bin\Debug\Arbiter.Test.dll"); RemoteTestRunner remoteTestRunner = new RemoteTestRunner(); remoteTestRunner.Load(testPackage); remoteTestRunner.Run(new NullListener(), new SingleTestFilter("StartWithOneTeam"), false, LoggingThreshold.Error); }
public SessionResults RunAssembly(Assembly assembly) { var remoteTestRunner = new RemoteTestRunner(0); var package = SetupTestPackager(assembly); remoteTestRunner.Load(package); var listener = new GilesNUnitEventListener(); remoteTestRunner.Run(listener); return(listener.SessionResults); }
private TestRunner MakeRemoteTestRunner(AppDomain runnerDomain) { Type runnerType = typeof(RemoteTestRunner); object obj = runnerDomain.CreateInstanceAndUnwrap( runnerType.Assembly.FullName, runnerType.FullName, false, BindingFlags.Default, null, new object[] { this.ID }, null, null, null); RemoteTestRunner runner = (RemoteTestRunner)obj; return(runner); }
private TestResult runTest() { CoreExtensions.Host.InitializeService(); TestPackage testPackage = new TestPackage(this.path); RemoteTestRunner rtr = new RemoteTestRunner(); rtr.Load(testPackage); TestResult tr = rtr.Run(new NullListener(), TestFilter.Empty, false, LoggingThreshold.Error); XmlResultWriter xmlw = new XmlResultWriter(Directory.GetCurrentDirectory() + @"\TempResults\testResult.xml"); xmlw.SaveTestResult(tr); return(tr); }
private TestRunner MakeRemoteTestRunner(AppDomain runnerDomain) { object obj = runnerDomain.CreateInstanceAndUnwrap( typeof(RemoteTestRunner).Assembly.FullName, typeof(RemoteTestRunner).FullName, false, BindingFlags.Default, null, null, null, null, null); RemoteTestRunner runner = (RemoteTestRunner)obj; runner.Out = this.outWriter; runner.Error = this.errorWriter; return(runner); }
private UnitTester(string testAssembly) { var testPackage = new TestPackage(Path.GetFileNameWithoutExtension(testAssembly)); testPackage.Assemblies.Add(testAssembly); // Create a new appdomain with the appropriate working directory. // This is required so that we don't accidentially load the wrong dependencies. var setup = new AppDomainSetup(); setup.ApplicationBase = Path.GetDirectoryName(testAssembly); domain = AppDomain.CreateDomain("TestDomain", null, setup); runner = RemoteTestRunner.CreateInstance(domain, 0); runner.Load(testPackage); }
public void Run() { if (!File.Exists(_path)) { return; } var testPackage = new TestPackage(_path); var remoteTestRunner = new RemoteTestRunner(); if (!remoteTestRunner.Load(testPackage)) { return; } var testResult = remoteTestRunner.Run(_eventListener, TestFilter.Empty, false, LoggingThreshold.Error); }
public TestResult Run(EventListener listener, ITestFilter filter, string path, string suiteName, List <string> supportAssemblies) { InitSupportAssemblies(supportAssemblies); if (filter == null) { filter = TestFilter.Empty; } RemoteTestRunner tr = new RemoteTestRunner(); TestPackage package = new TestPackage(path); if (!string.IsNullOrEmpty(suiteName)) { package.TestName = suiteName; } tr.Load(package); return(tr.Run(listener, filter, false, LoggingThreshold.All)); }
public TestRunner GetTestRunner() { //Doesn't help... //if (!CoreExtensions.Host.Initialized) // CoreExtensions.Host.InitializeService(); var pack = new TestPackage(_assemblyLocation); pack.ConfigurationFile = _assemblyLocation + ".config"; var nu = new RemoteTestRunner(); //var nu = new SimpleTestRunner(Thread.CurrentThread.ManagedThreadId); //var nu = new ThreadedTestRunner(new RemoteTestRunner()); if (!nu.Load(pack)) { throw new ApplicationException("what... very rude stuff happened"); } return(nu); }
private void DebugTests(IEnumerable <TestDetails> selectedTests) { if (_testRunnerTask == null) { _viewModel.CanRunTests = false; _viewModel.TestsAreRunning = true; _testRunnerTask = new TaskFactory().StartNew(() => { RemoteTestRunner runner = new RemoteTestRunner(_outputWriter); runner.DebugTests(selectedTests, _debugAttacher); _testRunnerTask = null; _viewModel.CanRunTests = true; _viewModel.TestsAreRunning = false; }); } }
public SessionResults RunAssembly(Assembly assembly, IEnumerable <string> filters) { this.filters = filters; var remoteTestRunner = new RemoteTestRunner(0); var package = SetupTestPackager(assembly); remoteTestRunner.Load(package); var listener = new GilesNUnitEventListener(); if (filters.Count() == 0) { remoteTestRunner.Run(listener); } else { remoteTestRunner.Run(listener, GetFilters()); } return(listener.SessionResults); }
public override void ExecuteTest(object instance, string testId, string methodName) { using (RemoteTestRunner testRunner = new RemoteTestRunner()) { TestPackage package = new TestPackage("FieldTest"); package.Assemblies.Add(instance.GetType().Assembly.Location); testRunner.Load(package); var testCount = testRunner.CountTestCases(new NameFilter()); var testToRun = GetMatchingTest(methodName, testRunner.Test); var testFilter = new NameFilter(testToRun.TestName); TestResult result = testRunner.Run(new NullListener(), testFilter); if (result.IsSuccess) { _testResultReporter.ReportTestResult(testId, "Passed", string.Empty); } else { result = GetMatchingTestResult(methodName, result); if (result != null) { if (result.ResultState == ResultState.Inconclusive) { _testResultReporter.ReportTestResult(testId, "Inconclusive", string.Format("{0} {1}", result.Message, result.StackTrace)); } else { _testResultReporter.ReportTestResult(testId, "Failed", string.Format("{0} {1}", result.Message, result.StackTrace)); } } else { _testResultReporter.ReportTestResult(testId, "Failed", string.Empty); } } testRunner.Unload(); } }
private TestResult RunTestsInAssemblies(IList assemblies, ITestFilter testfilter) { // Note: in order for nunit to unload assembly (not lock it) // we are using a modified version of nunit.core.dll (and the dependent nunit.interfaces.dll) // if the nunit dlls are updated this is what needs to be changed: // in TestAssemblyBuilder class in Load method, // change "assembly = Assembly.Load(assemblyName);" // to "assembly = Assembly.Load(File.ReadAllBytes(path));" TestPackage theTestPackage = new TestPackage("All Dlls", assemblies); theTestPackage.Settings.Add("UseThreadedRunner", false); theTestPackage.Settings.Add("DomainUsage", DomainUsage.None); RemoteTestRunner testRunner = new RemoteTestRunner(); testRunner.Load(theTestPackage); TestResult testResult = testRunner.Run(NullListener.NULL, testfilter, false, LoggingThreshold.Off); // Dispose testRunner.Unload(); testRunner.Dispose(); return(testResult); }
public static WebSharper.UI.Doc MainDoc(View <CalculatorViewModel> viewCalculator, Var <CalculatorViewModel> varCalculator) { // Page visibility without state machine var page = Var.Create(Single); // Setup the reactive ViewState storage and the test button. var viewState = Var.Create(""); var testSummary = new ListModel <string, string>(s => s); return(WebSharper.UI.Doc.ConcatMixed( input(viewState, attr.type("hidden")) , new Template.Index.Main() // Test button with result summary .Test(async(el, ev) => { var result = await RemoteTestRunner.Run("asptest.websharper.spa"); testSummary.Clear(); testSummary.AppendMany(result.Summary); if (!result.Passed) { JS.Window.Location.Assign(TestResultSite.ResultXmlPath); } }) .TestSummaryContainer( testSummary.View.DocSeqCached((string x) => new Template.Index.TestSummaryItem().Line(x).Doc() ) ) .ResultXmlPath(TestResultSite.ResultXmlPath) .Doc() , Page(page, viewCalculator, varCalculator) )); }
/// <summary> /// Main page as template. /// </summary> /// <returns></returns> public static WebSharper.UI.Doc IndexDoc() { var testSummary = new ListModel <string, string>(s => s); return(new Template.Index.Main() // Links to sub-pages .WithStatic((el, ev) => { WithStaticDoc().RunById("page"); }) .WithStorage((el, ev) => { WithStorageDoc().RunById("page"); }) // Test button with result summary .Test(async(el, ev) => { var result = await RemoteTestRunner.Run("minimaltest.websharper.spa"); testSummary.Clear(); testSummary.AppendMany(result.Summary); if (!result.Passed) { JS.Window.Location.Assign(TestResultSite.ResultXmlPath); } }) .TestSummaryContainer( testSummary.View.DocSeqCached((string x) => new Template.Index.TestSummaryItem().Line(x).Doc() ) ) .ResultXmlPath(TestResultSite.ResultXmlPath) .Doc()); }
public void generateAndRunVBObjectTests() { int i = 0; DirectoryInfo d = new DirectoryInfo(Directory.GetCurrentDirectory()); while (true) { i++; if (i >= 20) { throw new ApplicationException("could not get a dir with name GeneratorTests"); } d = d.Parent; if (d.Name == "GeneratorTests") { break; } } string path = d.FullName + "\\VbObjectTestsTmp.cs"; if (File.Exists(path)) { File.Delete(path); } File.Copy(d.FullName + "\\CSharpObjectTests.cs", path); string readText = File.ReadAllText(path); readText = readText.Replace("using CsModelObjects;", "using ModelLibVBGenCode.VbBusObjects;"); readText = readText.Replace("using CsModelMappers;", "using ModelLibVBGenCode.VbBusObjects.DBMappers;"); //readText = readText.Replace("DateTime hireDate=new", "dim hireDate as DateTime=new"); readText = readText.Replace("namespace GeneratorTests {", "namespace GeneratorTests.VB {"); readText = readText.Replace("public class CSharpObjectTests {", "public class VBObjectTests {"); readText = readText.Replace("public void createCsRecords()", "public void createVbRecords()"); readText = readText.Replace("[TestClass]", "[NUnit.Framework.TestFixture]"); readText = readText.Replace("[TestMethod]", "[NUnit.Framework.Test]"); readText = readText.Replace("using Microsoft.VisualStudio.TestTools.UnitTesting;", "using NUnit.Framework;"); readText = readText.Replace("Assert.", "NUnit.Framework.Assert."); readText = readText.Replace("public static void MyClassInitialize(TestContext testContext)", "public static void MyClassInitialize()"); readText = readText.Replace("[ClassInitialize()]", "[NUnit.Framework.SetUp]"); readText = readText.Replace("[ClassCleanup()]", "[NUnit.Framework.TearDown]"); readText = readText.Replace("//NUnit.Framework.NUnit.Framework.Assert.IsTrue(false)", "NUnit.Framework.Assert.IsTrue(false);"); readText = readText.Replace("//DBUtils.Current().ConnString=", "org.model.lib.db.DBUtils.Current().ConnString=\"" + DBUtils.Current().ConnString.Replace("\\", "\\\\") + "\";"); readText = readText.Replace("EnumProjectType.EXTERNAL", "ModelLibVBGenCode.EnumProjectType.EXTERNAL"); readText = readText.Replace("void testCSharp", "void testVBNet"); File.WriteAllText(path, readText); CSharpCodeProvider provider = new CSharpCodeProvider(); CompilerParameters cp = new CompilerParameters(); // this line is here otherwise ModelLibVBGenCode is not returned // in call to this.GetType().Assembly.GetReferencedAssemblies ModelLibVBGenCode.VbBusObjects.Employee e = null; NUnit.Framework.Guard x = null; // note: DO NOT REMOVE! var assemblies = this.GetType().Assembly.GetReferencedAssemblies().ToList(); var assemblyLocations = assemblies.Select(a => Assembly.ReflectionOnlyLoad(a.FullName).Location); var lstAssemblyLocations = assemblyLocations.Where(a => !a.Contains("Microsoft.VisualStudio.QualityTools.UnitTestFramework")).ToList(); //Assembly.ReflectionOnlyLoad("") cp.ReferencedAssemblies.AddRange(lstAssemblyLocations.ToArray()); cp.GenerateInMemory = false; // True - memory generation, false - external file generation cp.GenerateExecutable = false; // True - exe file generation, false - dll file generation CompilerResults results = provider.CompileAssemblyFromSource(cp, readText); Assert.AreEqual(0, results.Errors.Count, "There should be no compilation errors, first error was:" + (results.Errors.Count > 0 ? results.Errors[0].ErrorText : "")); CoreExtensions.Host.InitializeService(); TestPackage package = new TestPackage(results.CompiledAssembly.Location); RemoteTestRunner remoteTestRunner = new RemoteTestRunner(); remoteTestRunner.Load(package); TestResult result = remoteTestRunner.Run(new NullListener(), TestFilter.Empty, false, LoggingThreshold.All); Assert.IsTrue(result.HasResults, " must have test results "); Assert.IsTrue(result.IsSuccess, "dynamic vb tests must return success "); }
public NUnitTestRunner() { State = TestRunnerState.Idle; _testRunner = new RemoteTestRunner(); }
public static void Run(string loc, string[] args) { MainArgs ma = MainArgs.ValueOf(args); string excludes = ma.Get("exclude", null); string includes = ma.Get("include", null); string outfile = ma.Get("out", "TestResult.xml"); CoreExtensions.Host.InitializeService(); TestSuiteBuilder builder = new TestSuiteBuilder(); TestPackage testPackage = new TestPackage(loc); RemoteTestRunner remoteTestRunner = new RemoteTestRunner(); remoteTestRunner.Load(testPackage); TestSuite suite = builder.Build(testPackage); TestSuite root = suite.Tests[0] as TestSuite; List <TestFixture> fixtures = new List <TestFixture>(); ScanFixtures(root, fixtures); Console.WriteLine("--------------- {0} TextFixtures --------------- \n", fixtures.Count); //TestName testName = ((TestMethod) ((TestFixture) test.Tests[0]).Tests[0]).MethodName; ITestFilter filter = null; bool hasInclude = !string.IsNullOrEmpty(includes); bool hasExclude = !string.IsNullOrEmpty(excludes); if (hasInclude) { if (hasExclude) { // incldue+exclude; exclude first filter = new AndFilter(new ITestFilter[] { new NotFilter(new CategoryFilter(excludes.Split(','))), new SimpleNameFilter(includes.Split(',')), }); } else { // include filter = new SimpleNameFilter(includes.Split(',')); } } else // no include { if (hasExclude) { // Only exclude filter = new NotFilter(new CategoryFilter(excludes.Split(','))); } else { // none filter = new TrueFilter(); } } int succCnt = 0, failCnt = 0, errorCnt = 0, assertCnt = 0; TestResult tr = new TestResult(new TestName()); RunEventListener eventLsn = new RunEventListener(); foreach (TestFixture tf in fixtures) { TestResult result = tf.Run(eventLsn, filter); FixtureResult fr = null; if (result.Results != null) { fr = new FixtureResult(result); succCnt += fr.succCnt; failCnt += fr.failCnt; errorCnt += fr.errorCnt; assertCnt += fr.assertCnt; Console.WriteLine(" Done: " + fr.ToString()); } else { Console.WriteLine(" Done: no result."); } tr.AddResult(result); } if (failCnt + errorCnt == 0) { Console.WriteLine( @"========================================= Test Success! Cases: {0}, asserts: {1} =========================================", succCnt, assertCnt); } else { Console.WriteLine( @"================================================================================= Test with errors: Cases: {0}, asserts: {4}, Succ: {1}, fail:{2}, error: {3} =================================================================================", succCnt + errorCnt + failCnt, succCnt, failCnt, errorCnt, assertCnt); } XmlResultWriter w = new XmlResultWriter(outfile); w.SaveTestResult(tr); Console.WriteLine("Result save to: {0}", outfile); }
public void CreateRunner() { runner = new RemoteTestRunner(); assemblies = new string[] { testsDll, mockDll }; }
public TestRun() { remoteTesRunner = new RemoteTestRunner(); }