private static TestResult RunTests( string assemFile, ConsoleListener l ) { TestPackage testPackage = new TestPackage( assemFile ); RemoteTestRunner remoteTestRunner = new RemoteTestRunner(); remoteTestRunner.Load( testPackage ); return remoteTestRunner.Run( l, TestFilter.Empty, false, LoggingThreshold.Debug ); }
public override bool Load(TestPackage package) { log.Info("Loading Test Package " + package.Name ); // Initialize ExtensionHost if not already done if ( !CoreExtensions.Host.Initialized ) CoreExtensions.Host.InitializeService(); // Delayed creation of downstream runner allows us to // use a different runner type based on the package bool useThreadedRunner = package.GetSetting( "UseThreadedRunner", true ); TestRunner runner = new SimpleTestRunner( this.runnerID ); if (useThreadedRunner) { ApartmentState apartmentState = (ApartmentState)package.GetSetting("ApartmentState", ApartmentState.Unknown); ThreadPriority priority = (ThreadPriority)package.GetSetting("ThreadPriority", ThreadPriority.Normal); runner = new ThreadedTestRunner(runner, apartmentState, priority); } this.TestRunner = runner; if( base.Load (package) ) { log.Info("Loaded package successfully" ); return true; } else { log.Info("Package load failed" ); return false; } }
public static void RunAsync (string[] args) { Paths.SetStandardWorkingDirectory (); File.WriteAllText ("status.txt", "running"); var runOptions = RunOptions.Parse (args); if (runOptions.ShouldShowHelp) { runOptions.ShowHelp (); return; } CoreExtensions.Host.InitializeService (); var assembly = Assembly.GetExecutingAssembly (); var runner = new ThreadedTestRunner(new SimpleTestRunner()); TestPackage package = new TestPackage (assembly.GetName ().Name); package.Assemblies.Add (assembly.Location); if (!runner.Load (package)) { Console.WriteLine ("Could not find the tests."); return; } var listener = new MobileListener (runOptions); var filter = new AggregateTestFilter (runOptions.Filters); runner.BeginRun (listener, filter, false, LoggingThreshold.Warn); }
public override bool Load( TestPackage package ) { Unload(); try { if ( domain == null ) { domain = DomainManager.CreateDomain( package ); } if ( agent == null ) { agent = DomainAgent.CreateInstance( domain ); agent.Start(); } if ( TestRunner == null ) { TestRunner = agent.CreateRunner( ID ); } return TestRunner.Load( package ); } catch { Unload(); throw; } }
protected void Page_Load(object sender, EventArgs e) { // Initialise data table to hold test results _results.Columns.Add("test"); _results.Columns.Add("result"); _results.Columns.Add("time"); _results.Columns.Add("message"); _results.Columns.Add("class"); // Initialise controls lblResult.Text = ""; ltlStats.Text = ""; // Initialise NUnit CoreExtensions.Host.InitializeService(); // Find tests in current assembly _testPackage = new TestPackage(Assembly.GetExecutingAssembly().Location); if (!IsPostBack) { var testSuite = new TestSuiteBuilder().Build(_testPackage); var categoryManager = new CategoryManager(); categoryManager.AddAllCategories(testSuite); cblCategories.DataSource = (from string cat in categoryManager.Categories select cat).OrderBy(x => x); cblCategories.DataBind(); } }
public void RunAllAcceptanceTests() { //Define the name of itself var assemblyName = @"NBi.Testing.dll"; //Instantiate a SimpleTestRunner CoreExtensions.Host.InitializeService(); SimpleTestRunner runner = new SimpleTestRunner(); //Define the test package as all the tests of this assembly in the class RuntimeOverrider //The assembly (and so the tests) will be filtered based on TestName TestPackage package = new TestPackage( "Test"); package.TestName = "NBi.Testing.Acceptance.RuntimeOverrider"; //Filter package.Assemblies.Add(assemblyName); //Load the tests from the filtered package (so we don't need to filter again!) if( runner.Load(package) ) { //Run all the tests (Have I said I've previsously filtered ? ... No seriously you read this kind of comment?) TestResult result = runner.Run( new NullListener(), TestFilter.Empty, false, LoggingThreshold.Off ); //Ensure the acceptance test suite is fully positive! Assert.That(result.IsSuccess, Is.True); } else Assert.Fail("Unable to load the TestPackage from assembly '{0}'", assemblyName); }
public override bool Load(TestPackage package) { log.Info("Loading Test Package " + package.Name ); // Initialize ExtensionHost if not already done if ( !CoreExtensions.Host.Initialized ) CoreExtensions.Host.InitializeService(); // Delayed creation of downstream runner allows us to // use a different runner type based on the package bool useThreadedRunner = package.GetSetting( "UseThreadedRunner", true ); TestRunner runner = new SimpleTestRunner( this.runnerID ); if ( useThreadedRunner ) runner = new ThreadedTestRunner( runner ); this.TestRunner = runner; if( base.Load (package) ) { log.Info("Loaded package successfully" ); return true; } else { log.Info("Package load failed" ); return false; } }
public void LoadFixture() { TestPackage package = new TestPackage( testsDll ); package.TestName = "NUnit.Core.Tests.SuiteBuilderTests"; Test suite= builder.Build( package ); Assert.IsNotNull(suite, "Unable to build suite"); }
public ITest LoadTests(IEnumerable<string> assemblies) { var testRunner = new SimpleTestRunner(); var enumerable = assemblies as IList<string> ?? assemblies.ToList(); _log.Debug("Creating NUnit package for files " + string.Join(", ", enumerable)); var package = new TestPackage("", enumerable.ToList()); package.Settings["RuntimeFramework"] = new RuntimeFramework(RuntimeType.Net, Environment.Version); package.Settings["UseThreadedRunner"] = false; // lock (this) // { _log.Debug("Loading NUnit package: " + package); bool load = testRunner.Load(package); if (!load) { throw new Exception("Tests load result: false."); } var t = testRunner.Test; testRunner.Unload(); return t; // } }
public override bool Load( TestPackage package ) { Unload(); log.Info("Loading " + package.Name); try { if ( this.domain == null ) this.domain = Services.DomainManager.CreateDomain( package ); if (this.agent == null) { this.agent = DomainAgent.CreateInstance(domain); this.agent.Start(); } if ( this.TestRunner == null ) this.TestRunner = this.agent.CreateRunner( this.ID ); log.Info( "Loading tests in AppDomain, see {0}_{1}.log", domain.FriendlyName, Process.GetCurrentProcess().Id); return TestRunner.Load( package ); } catch { log.Error("Load failure"); Unload(); throw; } }
public void DiscoverSuite() { TestPackage package = new TestPackage( testData ); package.TestName = "NUnit.TestData.SuiteBuilderTests.Suite"; Test suite = builder.Build( package ); Assert.IsNotNull(suite, "Could not discover suite attribute"); }
/// <summary> /// Runs all tests</summary> /// <param name="displayName">Name of the test, which is normally the executing /// assembly's Location.</param> /// <param name="assemblyPaths">List of assemblies to actually test</param> /// <returns>0 if tests ran successfully, a negative number otherwise</returns> public static int RunAllTests(string displayName, List<string> assemblyPaths) { TestRunner runner; try { var package = new TestPackage(displayName, assemblyPaths); runner = new DefaultTestRunnerFactory().MakeTestRunner(package); runner.Load(package); } catch (System.IO.FileLoadException) { // likely caused by ATF source zip file downloaded from internet without unblocking it Console.WriteLine("NUnit failed to load {0}", displayName); Console.WriteLine(@"Possibly need to unblock the downloaded ATF source zip file before unzipping"); Console.WriteLine(@"(right click on the zip file -> Properties -> Unblock)"); return -3; } catch (Exception) { return -2; } runner.Run(new UnitTestListener()); if (runner.TestResult.IsFailure) return -1; return 0; }
public override bool Load(TestPackage package) { log.Info("Loading " + package.Name); Unload(); RuntimeFramework runtimeFramework = package.Settings["RuntimeFramework"] as RuntimeFramework; if ( runtimeFramework == null ) runtimeFramework = RuntimeFramework.CurrentFramework; bool loaded = false; try { if (this.agent == null) this.agent = Services.TestAgency.GetAgent( runtimeFramework, 20000 ); if (this.agent == null) return false; if ( this.TestRunner == null ) this.TestRunner = agent.CreateRunner(this.runnerID); loaded = base.Load (package); return loaded; } finally { // Clean up if the load failed if ( !loaded ) Unload(); } }
protected void Page_Load(object sender, EventArgs e) { // Initialise data table to hold test results m_results.Columns.Add("test"); m_results.Columns.Add("result"); m_results.Columns.Add("time"); m_results.Columns.Add("message"); m_results.Columns.Add("class"); // Initialise controls lblResult.Text = ""; ltlStats.Text = ""; // Initialise NUnit CoreExtensions.Host.InitializeService(); // Find tests in current assembly TestPackage package = new TestPackage(Assembly.GetExecutingAssembly().Location); m_testSuite = new TestSuiteBuilder().Build(package); if (!IsPostBack) { // Display category filters StringCollection coll = new StringCollection(); GetCategories((TestSuite)m_testSuite, coll); string[] cats = new string[coll.Count]; coll.CopyTo(cats, 0); Array.Sort(cats); cblCategories.DataSource = cats; cblCategories.DataBind(); } }
public static void Main() { // Set common application locale, check 'app.config' for this property SetLocale(ConfigurationManager.AppSettings["Locale"]); // Get test data from scenario file Scenario scenario = GetScenario(ConfigurationManager.AppSettings["Nunit.Runner.Scenario"]); string suite = scenario.Name; IList<string> testClasses = scenario.Tests; // Start tests CoreExtensions.Host.InitializeService(); SimpleTestRunner runner = new SimpleTestRunner(); TestPackage package = new TestPackage(suite); string loc = Assembly.GetExecutingAssembly().Location; package.Assemblies.Add(loc); try { if (runner.Load(package)) { TestResult result = runner.Run(new RunnerListener(), new ClassTestFilter(testClasses), true, LoggingThreshold.Debug); } } catch (Exception e) { _log.Error(e.Message, e); } }
public void LoadAssemblyWithSuite() { TestPackage package = new TestPackage( mockDll ); package.TestName = "NUnit.Tests.Assemblies.MockSuite"; runner.Load( package ); Assert.IsNotNull(runner.Test, "Unable to build suite"); }
public void LoadFixture() { TestPackage package = new TestPackage( "Multiple Assemblies", assemblies ); package.TestName = "NUnit.Tests.Assemblies.MockTestFixture"; TestSuite suite = builder.Build( package ); Assert.IsNotNull( suite ); Assert.AreEqual( MockTestFixture.Tests, suite.TestCount ); }
public void LoadSuite() { TestPackage package = new TestPackage( testsDll ); package.TestName = "NUnit.Core.Tests.AllTests"; Test suite= builder.Build( package ); Assert.IsNotNull(suite, "Unable to build suite"); Assert.AreEqual( 3, suite.Tests.Count ); }
private static TestRunner MakeTestRunner(string testAssemblyName) { TestPackage package = new TestPackage(testAssemblyName); TestRunner runner = new DefaultTestRunnerFactory().MakeTestRunner(package); runner.Load(package); return runner; }
public void LoadTestFixtureFromAssembly() { TestSuiteBuilder builder = new TestSuiteBuilder(); TestPackage package = new TestPackage( testsDll ); package.TestName = "NUnit.Tests.Assemblies.MockTestFixture"; Test suite= builder.Build( package ); Assert.IsNotNull(suite); }
public void LoadAssemblyWithoutNamespaces() { TestPackage package = new TestPackage( testsDll ); package.Settings["AutoNamespaceSuites"] = false; Test suite = builder.Build( package ); Assert.IsNotNull(suite, "Unable to build suite" ); Assert.Greater( suite.Tests.Count, 1 ); Assert.AreEqual( "TestFixture", ((ITest)suite.Tests[0]).TestType ); }
public void LoadNamespaceAsSuite() { TestPackage package = new TestPackage( testsDll ); package.TestName = "NUnit.Core.Tests"; Test suite= builder.Build( package ); Assert.IsNotNull( suite ); Assert.AreEqual( testsDll, suite.TestName.Name ); Assert.AreEqual( "NUnit", ((Test)suite.Tests[0]).TestName.Name ); }
private Test loadFixture( Type type ) { TestPackage package = new TestPackage( type.Module.Name ); package.TestName = type.FullName; Test suite= builder.Build( package ); Assert.IsNotNull(suite); return suite; }
public void Init() { domain = new TestDomain(); TestPackage package = new TestPackage( name ); package.Assemblies.Add( path1 ); package.Assemblies.Add( path2 ); domain.Load( package ); loadedSuite = domain.Test; }
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); }
private static TestPackage SetupTestPackager(Assembly assembly) { var package = new TestPackage(assembly.FullName, new[] { assembly.Location }); package.BasePath = GetAssemblyDirectory(assembly).FullName; package.ConfigurationFile = GetTestAssemblyConfigurationFile(assembly); return package; }
/// <summary> /// Selects a target runtime framework for a TestPackage based on /// the settings in the package and the assemblies themselves. /// The package RuntimeFramework setting may be updated as a /// result and the selected runtime is returned. /// </summary> /// <param name="package">A TestPackage</param> /// <returns>The selected RuntimeFramework</returns> public RuntimeFramework SelectRuntimeFramework(TestPackage package) { RuntimeFramework currentFramework = RuntimeFramework.CurrentFramework; RuntimeFramework requestedFramework = package.Settings["RuntimeFramework"] as RuntimeFramework; log.Debug("Current framework is {0}", currentFramework); if (requestedFramework == null) log.Debug("No specific framework requested"); else log.Debug("Requested framework is {0}", requestedFramework); RuntimeType targetRuntime = requestedFramework == null ? RuntimeType.Any : requestedFramework.Runtime; Version targetVersion = requestedFramework == null ? RuntimeFramework.DefaultVersion : requestedFramework.FrameworkVersion; if (targetRuntime == RuntimeType.Any) targetRuntime = currentFramework.Runtime; if (targetVersion == RuntimeFramework.DefaultVersion) { if (Services.UserSettings.GetSetting("Options.TestLoader.RuntimeSelectionEnabled", true)) foreach (string assembly in package.Assemblies) { using (AssemblyReader reader = new AssemblyReader(assembly)) { string vString = reader.ImageRuntimeVersion; if (vString.Length > 1) // Make sure it's a valid dot net assembly { Version v = new Version(vString.Substring(1)); log.Debug("Assembly {0} uses version {1}", assembly, v); if (v > targetVersion) targetVersion = v; } } } else targetVersion = RuntimeFramework.CurrentFramework.ClrVersion; RuntimeFramework checkFramework = new RuntimeFramework(targetRuntime, targetVersion); if (!checkFramework.IsAvailable || !Services.TestAgency.IsRuntimeVersionSupported(targetVersion)) { log.Debug("Preferred version {0} is not installed or this NUnit installation does not support it", targetVersion); if (targetVersion < currentFramework.FrameworkVersion) targetVersion = currentFramework.FrameworkVersion; } } RuntimeFramework targetFramework = new RuntimeFramework(targetRuntime, targetVersion); package.Settings["RuntimeFramework"] = targetFramework; log.Debug("Test will use {0} framework", targetFramework); return targetFramework; }
/// <summary> /// Build a suite based on a TestPackage /// </summary> /// <param name="package">The TestPackage</param> /// <returns>A TestSuite</returns> public TestSuite Build( TestPackage package ) { bool autoNamespaceSuites = package.GetSetting( "AutoNamespaceSuites", true ); bool mergeAssemblies = package.GetSetting( "MergeAssemblies", false ); TestExecutionContext.CurrentContext.TestCaseTimeout = package.GetSetting("DefaultTimeout", 0); if ( package.IsSingleAssembly ) return BuildSingleAssembly( package ); string targetAssemblyName = null; if( package.TestName != null && package.Assemblies.Contains( package.TestName ) ) { targetAssemblyName = package.TestName; package.TestName = null; } TestSuite rootSuite = new ProjectRootSuite( package.FullName ); NamespaceTreeBuilder namespaceTree = new NamespaceTreeBuilder( rootSuite ); builders.Clear(); foreach(string assemblyName in package.Assemblies) { if ( targetAssemblyName == null || targetAssemblyName == assemblyName ) { TestAssemblyBuilder builder = new TestAssemblyBuilder(); builders.Add( builder ); Test testAssembly = builder.Build( assemblyName, package.TestName, autoNamespaceSuites && !mergeAssemblies ); if ( testAssembly != null ) { if (!mergeAssemblies) { rootSuite.Add(testAssembly); } else if (autoNamespaceSuites) { namespaceTree.Add(testAssembly.Tests); rootSuite = namespaceTree.RootSuite; } else { foreach (Test test in testAssembly.Tests) rootSuite.Add(test); } } } } ProviderCache.Clear(); if (rootSuite.Tests.Count == 0) return null; return rootSuite; }
public void LoadAssemblyWithoutNamespaces() { TestPackage package = new TestPackage( mockDll ); package.Settings["AutoNamespaceSuites"] = false; Assert.IsTrue(runner.Load( package ), "Unable to load assembly" ); ITest test = runner.Test; Assert.IsNotNull( test ); Assert.AreEqual( MockAssembly.Fixtures, test.Tests.Count ); Assert.AreEqual( "MockTestFixture", ((ITest)test.Tests[0]).TestName.Name ); }
public void CreatePackages() { package1 = new TestPackage(MockAssembly.AssemblyPath); package2 = new TestPackage("TestSuite", assemblies); // Set current framework explicitly to avoid running out of process // unless explicitly called for by derived test. package1.Settings["RuntimeFramework"] = currentFramework; package2.Settings["RuntimeFramework"] = currentFramework; }
/// <summary> /// Build a suite based on a TestPackage /// </summary> /// <param name="package">The TestPackage</param> /// <returns>A TestSuite</returns> public TestSuite Build(TestPackage package) { bool autoNamespaceSuites = package.GetSetting("AutoNamespaceSuites", true); bool mergeAssemblies = package.GetSetting("MergeAssemblies", false); TestContext.TestCaseTimeout = package.GetSetting("DefaultTimeout", 0); if (package.IsSingleAssembly) { return(BuildSingleAssembly(package)); } string targetAssemblyName = null; if (package.TestName != null && package.Assemblies.Contains(package.TestName)) { targetAssemblyName = package.TestName; package.TestName = null; } TestSuite rootSuite = new ProjectRootSuite(package.FullName); NamespaceTreeBuilder namespaceTree = new NamespaceTreeBuilder(rootSuite); builders.Clear(); foreach (string assemblyName in package.Assemblies) { if (targetAssemblyName == null || targetAssemblyName == assemblyName) { TestAssemblyBuilder builder = new TestAssemblyBuilder(); builders.Add(builder); Test testAssembly = builder.Build(assemblyName, package.TestName, autoNamespaceSuites && !mergeAssemblies); if (testAssembly != null) { if (!mergeAssemblies) { rootSuite.Add(testAssembly); } else if (autoNamespaceSuites) { namespaceTree.Add(testAssembly.Tests); rootSuite = namespaceTree.RootSuite; } else { foreach (Test test in testAssembly.Tests) { rootSuite.Add(test); } } } } } ProviderCache.Clear(); if (rootSuite.Tests.Count == 0) { return(null); } return(rootSuite); }
public virtual bool Load(TestPackage package) { return(this.testRunner.Load(package)); }