Пример #1
0
        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)
            {
                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;
			}
		}
Пример #3
0
        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);
            }
        }
Пример #4
0
 public NunitTestRunner(string projectName)
 {
     _projectName = projectName;
     _eventListener = new TestResultsEventListener();
     CoreExtensions.Host.InitializeService();
     _testRunner = new SimpleTestRunner();
 }
Пример #5
0
		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;
			}
		}
Пример #6
0
        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;
//                }
               
            

        }
Пример #7
0
 public static void Main(string[] args)
 {
     CoreExtensions.Host.InitializeService();
     TestPackage package = new TestPackage("Test");
     package.Assemblies.Add(System.Reflection.Assembly.GetExecutingAssembly().Location);
     SimpleTestRunner runner = new SimpleTestRunner();
     if (runner.Load(package))
     {
         TestResult result = runner.Run(new NullListener(), TestFilter.Empty, true, LoggingThreshold.All);
         if (!result.IsSuccess)
             throw new Exception(result.Message);
     }
 }
Пример #8
0
 static void Main(string[] args)
 {
     var testDll = args[0];
     CoreExtensions.Host.InitializeService();
     TestRunner runner = new SimpleTestRunner();
     var package = new TestPackage(testDll);
     runner.Load(package);
     var tests = runner.Test.Tests;
     foreach (TestNode test in tests)
     {
         ProcessTestNode(test);
     }
 }
Пример #9
0
        static void Main(string[] args)
        {
            CoreExtensions.Host.InitializeService();
            SimpleTestRunner runner = new SimpleTestRunner();
            TestPackage package = new TestPackage("GivenITGuys");
            string loc = Assembly.GetExecutingAssembly().Location;
            package.Assemblies.Add(loc);
            if (runner.Load(package))
            {
                TestResult result = runner.Run(new NullListener(), TestFilter.Empty, false, LoggingThreshold.Off);

                new XmlResultWriter(@"ITGuysResult.xml").SaveTestResult(result);
            }
        }
Пример #10
0
        public List<TestResult> RunTests()
        {
            TestResultsEventListener eventListener = new TestResultsEventListener();
            CoreExtensions.Host.InitializeService();
            SimpleTestRunner runner = new SimpleTestRunner();

            TestPackage package = new TestPackage("TemplateTestClass");

            string loc = Assembly.GetExecutingAssembly().Location;
            package.Assemblies.Add(loc);

            if (runner.Load(package))
            {
                runner.Run(eventListener, TestFilter.Empty, true, LoggingThreshold.All);
            }
            return eventListener.ListResults;
        }
Пример #11
0
		public void LoadTestsFromCompiledAssembly()
		{
			CompilerResults results = compiler.CompileCode( goodCode );
			Assert.AreEqual( 0, results.NativeCompilerReturnValue );

			TestRunner runner = new SimpleTestRunner();

			try
			{
				Assert.IsTrue( runner.Load( new TestPackage( outputName ) ) );
				Assert.AreEqual( 2, runner.Test.TestCount );
			}
			finally
			{
				runner.Unload();
			}
		}
Пример #12
0
        public override bool Load(TestPackage package)
        {
            // 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;

            return base.Load (package);
        }
Пример #13
0
    protected void RunClick(object sender, EventArgs args)
    {
      var categories = from ListItem item in cblCategories.Items
                       where item.Selected
                       select item.Value;

      if(!categories.Any())
        categories = from ListItem item in cblCategories.Items
                       select item.Value;

      // Create a category filter
      var filter = new CategoryFilter(categories.ToArray());

      var runner = new SimpleTestRunner();
      runner.Load(_testPackage);

      var result = runner.Run(this, filter, true, LoggingThreshold.All);

      // Bind results to presentation
      gvResults.DataSource = _results;
      gvResults.DataBind();

      // Display statistics
      ltlStats.Text = string.Format("{0} out of {1} tests run in {2} seconds.", _executedCount, result.Test.TestCount, result.Time);

      if (_failedCount > 0)
        ltlStats.Text += string.Format("<br/>{0} {1} failed", _failedCount, _failedCount == 1 ? "test" : "tests");

      var skipped = result.Test.TestCount - _executedCount;
      if (skipped > 0)
        ltlStats.Text += string.Format("<br/>{0} {1} skipped", skipped, skipped == 1 ? "test" : "tests");

      lblResult.Text = "Suite " + (result.IsSuccess ? "Passed" : "Failed");
      if (result.IsSuccess)
        lblResult.CssClass = "passLabel";
      else
        lblResult.CssClass = "failLabel";
    }
Пример #14
0
        public override bool Load(TestPackage package)
        {
            // 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;

            return(base.Load(package));
        }
Пример #15
0
        public void RunTests()
        {
            // Create test runner
            var testRunner = new SimpleTestRunner();

            // Load this assembly to test runner
            var assemblies = new List<string>();
            assemblies.Add(GetType().Assembly.Location);

            var testPackage = new TestPackage(GetType().FullName, assemblies);

            bool loaded = testRunner.Load(testPackage);
            if (!loaded)
                throw new InvalidOperationException("Can't load this assembly into test package");

            // Run all tests in this assembly
            testRunner.BeginRun(this, this);
            testRunner.Wait();

            // Summarize
            TestResult testResult = testRunner.EndRun();
            Console.WriteLine("testResult={0}", testResult);
        }
Пример #16
0
        public Result Execute(ExternalCommandData revit, ref string message, ElementSet elements)
        {
            RevitCommandData = revit;

            // Run tests
            try
            {
                CoreExtensions.Host.InitializeService();
                var runner = new SimpleTestRunner();
                var package = new TestPackage("Test");
                string loc = Assembly.GetExecutingAssembly().Location;
                package.Assemblies.Add(loc);

                TestResult result;
                if (runner.Load(package))
                {
                    result = runner.Run(new NullListener(), TestFilter.Empty, true, LoggingThreshold.All);

                    MessageBox.Show(result.FullName);
                    MessageBox.Show(result.IsSuccess.ToString());
                    MessageBox.Show(result.Message);
                    MessageBox.Show(result.Results.Count.ToString());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                if (dynSettings.Writer != null)
                {
                    dynSettings.Writer.WriteLine(ex.Message);
                    dynSettings.Writer.WriteLine(ex.StackTrace);
                    dynSettings.Writer.WriteLine("Dynamo log ended " + DateTime.Now.ToString());
                }
            }

            return Result.Succeeded;
        }
        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);
            }
        }
Пример #18
0
        public static int Main(String[] args)
        {
            CoreExtensions.Host.InitializeService();
            SimpleTestRunner runner = new SimpleTestRunner();
            TestPackage package = new TestPackage( "Test" );

            string loc= Assembly.GetAssembly(typeof(UnpickleStackTest)).Location;
            Console.WriteLine("assembly="+loc);
            package.Assemblies.Add( loc );

            bool fail=true;
            if( runner.Load(package) )
            {
                Console.WriteLine("running tests");
                TestResult results = runner.Run( new MyListener() );
                fail=results.IsFailure;
            }

            Console.WriteLine("press enter to exit");
            Console.ReadLine();

            if(fail) return 10;
            else return 0;
        }
        private TestResult GenerateTestResults()
        {
            CoreExtensions.Host.InitializeService();
            loggerProvider.GetLogger()
                .Debug("Running tests from {testLibraryPath}", configurationProvider.TestLibraryPath);
            var testPackage = new TestPackage(configurationProvider.TestLibraryPath);
            var simpleTestRunner = new SimpleTestRunner();
            simpleTestRunner.Load(testPackage);

            var currentOut = Console.Out;
            var testResult = simpleTestRunner.Run(new NullListener(), new CategoryFilter("Smoke"), true, LoggingThreshold.All);
            Console.SetOut(currentOut);
            return testResult;
        }
Пример #20
0
        // ----------------------------------------------------------------------
        private static bool TestPackage( string packageName )
        {
            bool success = true;

            SimpleTestRunner runner = new SimpleTestRunner();
            TestPackage package = new TestPackage( packageName );
            if ( runner.Load( package ) )
            {
                TestResult result = runner.Run( new NullListener() );

                if ( result.IsSuccess )
                {
                    Console.WriteLine( "tests finished successfully" );
                }
                else
                {
                    success = false;
                    TestResultReport testReport = new TestResultReport( result );
                    foreach ( string failedTest in testReport.FailedTests )
                    {
                        Console.WriteLine( "failed test: {0}", failedTest );
                    }
                    foreach ( string errorTests in testReport.ErrorTests )
                    {
                        Console.WriteLine( "error test: {0}", errorTests );
                    }
                }
            }
            return success;
        }
Пример #21
0
		public static void RunMain (string [] args)
		{
			var runOptions = RunOptions.Parse (args);

			if (runOptions.ShouldShowHelp) {
				runOptions.ShowHelp ();
				return;
			}

			CoreExtensions.Host.InitializeService ();

			var assembly = Assembly.GetExecutingAssembly ();

			var runner = 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 CommandLineTestEventListener(runOptions);
			var filter = new AggregateTestFilter (runOptions.Filters);
			runner.Run (listener, filter, false, LoggingThreshold.Off);
		}
Пример #22
0
        public Result Execute(ExternalCommandData revit, ref string message, ElementSet elements)
        {
            DynamoLogger.Instance.StartLogging();

            try
            {
                m_revit = revit.Application;
                m_doc = m_revit.ActiveUIDocument;

                #region default level

                Level defaultLevel = null;
                var fecLevel = new FilteredElementCollector(m_doc.Document);
                fecLevel.OfClass(typeof(Level));
                defaultLevel = fecLevel.ToElements()[0] as Level;

                #endregion

                dynRevitSettings.Revit = m_revit;
                dynRevitSettings.Doc = m_doc;
                dynRevitSettings.DefaultLevel = defaultLevel;

                //create dynamo
                Regex r = new Regex(@"\b(Autodesk |Structure |MEP |Architecture )\b");
                string context = r.Replace(m_revit.Application.VersionName, "");

                var dynamoController = new DynamoController_Revit(DynamoRevitApp.env, DynamoRevitApp.updater, typeof(DynamoRevitViewModel), context);

                //flag to run evalauation synchronously, helps to
                //avoid threading issues when testing.
                dynamoController.Testing = true;

                //execute the tests
                Results = new DynamoRevitTestRunner();
                DynamoRevitTestResultsView resultsView = new DynamoRevitTestResultsView();
                resultsView.DataContext = Results;

                //http://stackoverflow.com/questions/2798561/how-to-run-nunit-from-my-code
                string assLocation = Assembly.GetExecutingAssembly().Location;
                FileInfo fi = new FileInfo(assLocation);
                string testLoc = Path.Combine(fi.DirectoryName, @"DynamoRevitTester.dll");

                //Tests must be executed on the main thread in order to access the Revit API.
                //NUnit's SimpleTestRunner runs the tests on the main thread
                //http://stackoverflow.com/questions/16216011/nunit-c-run-specific-tests-through-coding?rq=1
                CoreExtensions.Host.InitializeService();
                SimpleTestRunner runner = new SimpleTestRunner();
                TestSuiteBuilder builder = new TestSuiteBuilder();
                TestPackage package = new TestPackage("DynamoRevitTests", new List<string>() { testLoc });
                runner.Load(package);
                TestSuite suite = builder.Build(package);
                TestFixture fixture = null;
                FindFixtureByName(out fixture, suite, "DynamoRevitTests");
                if (fixture == null)
                    throw new Exception("Could not find DynamoRevitTests fixture.");

                foreach (var t in fixture.Tests)
                {
                    if (t is ParameterizedMethodSuite)
                    {
                        var paramSuite = t as ParameterizedMethodSuite;
                        foreach (var tInner in paramSuite.Tests)
                        {
                            if (tInner is TestMethod)
                                Results.Results.Add(new DynamoRevitTest(tInner as TestMethod));
                        }
                    }
                    else if (t is TestMethod)
                        Results.Results.Add(new DynamoRevitTest(t as TestMethod));
                }

                resultsView.ShowDialog();

            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                return Result.Failed;
            }

            return Result.Succeeded;
        }
Пример #23
0
        private testsuiteType RunTests(bool canReadData)
        {
            //http://stackoverflow.com/questions/2798561/how-to-run-nunit-from-my-code

            //Tests must be executed on the main thread in order to access the Revit API.
            //NUnit's SimpleTestRunner runs the tests on the main thread
            //http://stackoverflow.com/questions/16216011/nunit-c-run-specific-tests-through-coding?rq=1
            CoreExtensions.Host.InitializeService();
            var runner = new SimpleTestRunner();
            var builder = new TestSuiteBuilder();
            string testAssemblyLoc = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), testAssembly);

            var package = new TestPackage("RevitTestFramework", new List<string>() {testAssemblyLoc});
            runner.Load(package);
            TestSuite suite = builder.Build(package);

            TestFixture fixture = null;
            FindFixtureByName(out fixture, suite, fixtureName);
            if (fixture == null)
                throw new Exception(string.Format("Could not find fixture: {0}", fixtureName));

            InitializeResults();

            // If we can't read data, add a failed test result to root.
            if (!canReadData)
            {
                var currInvalid = Convert.ToInt16(resultsRoot.invalid);
                resultsRoot.invalid = currInvalid + 1;
                resultsRoot.testsuite.result = "Error";

                throw new Exception("Journal file's data map contains no information about tests.");
            }

            //find or create a fixture
            var fixtureResult = FindOrCreateFixtureResults(dynamoResults, fixtureName);

            //convert the fixture's results array to a list
            var runningResults = fixtureResult.results.Items.ToList();

            //if the test name is not specified
            //run all tests in the fixture
            if (string.IsNullOrEmpty(testName) || testName == "None")
            {
                var fixtureResults = RunFixture(fixture);
                runningResults.AddRange(fixtureResults);
            }
            else
            {
                var t = FindTestByName(fixture, testName);
                if (t != null)
                {
                    if (t is ParameterizedMethodSuite)
                    {
                        var paramSuite = t as ParameterizedMethodSuite;
                        runningResults.AddRange(
                            paramSuite.Tests.OfType<TestMethod>()
                                .Select(RunTest).Cast<object>());
                    }
                    else
                    {
                        var method = t as TestMethod;
                        if (method != null)
                        {
                            runningResults.Add(RunTest(method));
                        }
                    }
                }
                else
                {
                    //we have a journal file, but the specified test could not be found
                    var currInvalid = Convert.ToInt16(resultsRoot.invalid);
                    resultsRoot.invalid = currInvalid + 1;
                    resultsRoot.testsuite.result = "Error";
                }
            }

            fixtureResult.results.Items = runningResults.ToArray();
            return fixtureResult;
        }
Пример #24
0
            public void DoTest(string testLibraryPath)
            {
                Console.SetOut(new StubWriter());
                var listener = new Listener();
                CoreExtensions.Host.InitializeService();
                var package = new TestPackage(testLibraryPath);
                //package.AutoBinPath = true;
                //package.BasePath = Path.GetDirectoryName(TestLibraryPath);
                //package.ConfigurationFile = TestLibraryPath + ".config";
                TestRunner runner = new SimpleTestRunner();
                if (runner.Load(package))
                {
                    runner.Run(listener, TestFilter.Empty, true, LoggingThreshold.All);
                }
                //DebugTestResult(Console.Out, result);

                if (!listener.Messages.Any())
                {
                    listener.Messages.Add(Message.CreateError("No messages from listener"));
                }

                AppDomain.CurrentDomain.SetData(DATA_TEST_RESULTS_KEY, new Response(listener.Messages));
            }
Пример #25
0
        public static void RunMain(string [] args)
        {
            bool launchResults = true;
            bool performXslTransform = true;
            bool showHelp = false;

            var directory = Directory.GetCurrentDirectory ();

            string xmlResultsFile = Path.Combine (directory, "test_results.xml");
            string transformedResultsFile = Path.Combine (directory, "test_results.html");
            string xslTransformPath = Path.Combine ("Resources", "tests.xsl");
            string stdoutFile = Path.Combine (directory, "stdout.txt");
            var filters = new List<RegexFilter> ();
            var optionSet = new OptionSet () {
                { "i|include=", x => filters.Add(RegexFilter.Parse(x, FilterAction.Include)) },
                { "x|exclude=", x => filters.Add(RegexFilter.Parse(x, FilterAction.Exclude)) },
                { "no-launch-results", x => launchResults = false },
                { "no-xsl-transform", x => performXslTransform = false },
                { "xml-results=", x => xmlResultsFile = x },
                { "xsl-transform=", x => xslTransformPath = x },
                { "transformed-results=", x => transformedResultsFile = x },
                { "stdout=", x => stdoutFile = x },
            //				{ "v|verbose",  x => ++verbose },
                { "h|?|help",   x => showHelp = true },
            };

            List<string> extra = optionSet.Parse (args);
            if (extra.Count > 0)
                Console.WriteLine (
                    "Ignoring {0} unrecognized argument(s): {1}",
                    extra.Count, string.Join (", ", extra));

            if (showHelp) {
                ShowHelp (optionSet);
                System.Threading.Thread.Sleep (3000);
                return;
            }

            CoreExtensions.Host.InitializeService ();

            var assembly = Assembly.GetExecutingAssembly ();

            var simpleTestRunner = new SimpleTestRunner ();
            TestPackage package = new TestPackage (assembly.GetName ().Name);
            package.Assemblies.Add (assembly.Location);
            if (!simpleTestRunner.Load (package)) {
                Console.WriteLine ("Could not find the tests.");
                return;
            }

            var cli = new CommandLineInterface (filters);

            var result = simpleTestRunner.Run (cli, cli);

            var resultWriter = new XmlResultWriter (xmlResultsFile);
            resultWriter.SaveTestResult (result);

            if (performXslTransform) {
                var transform = new XslTransform ();
                transform.Load (xslTransformPath);
                transform.Transform (xmlResultsFile, transformedResultsFile);
            }

            File.WriteAllText (stdoutFile, cli._stdoutStandin.ToString ());

            if (performXslTransform && launchResults)
                System.Diagnostics.Process.Start (transformedResultsFile);
        }
Пример #26
0
        private object RunTests(ITestFilter filter)
        {
            if (runner != null && runner.Running)
            {
                while (runner.Running) { /*do nothing*/ }
                return GetTestResult(testResults);
            }

            using (runner = new SimpleTestRunner())
            {
                runner.Load(package);
                if (runner.Test == null)
                {
                    runner.Unload();
                    return new {text = "Unable to load the tests", status = "warning"};
                }

                TestResult result;
                try
                {
                    result = runner.Run(this, filter, true, LoggingThreshold.All);
                }
                catch (Exception e)
                {
                    return new {text = e.Message, status = "error"};
                }

                return result == null
                    ? new {text = "No results", status = "warning"}
                    : GetTestResult(testResults);
            }
        }
Пример #27
0
        public Result Execute(ExternalCommandData revit, ref string message, ElementSet elements)
        {
            AppDomain.CurrentDomain.AssemblyResolve += Dynamo.Utilities.AssemblyHelper.CurrentDomain_AssemblyResolve;

            //Get the data map from the running journal file.
            IDictionary<string, string> dataMap = revit.JournalData;

            try
            {
                RevitData.Application = revit.Application;
                RevitData.Document = RevitData.Application.ActiveUIDocument;

                bool canReadData = (0 < dataMap.Count);

                if (canReadData)
                {
                    if (dataMap.ContainsKey("testName"))
                    {
                        testName = dataMap["testName"];
                    }
                    if (dataMap.ContainsKey("fixtureName"))
                    {
                        fixtureName = dataMap["fixtureName"];
                    }
                    if (dataMap.ContainsKey("testAssembly"))
                    {
                        testAssembly = dataMap["testAssembly"];
                    }
                    if (dataMap.ContainsKey("resultsPath"))
                    {
                        resultsPath = dataMap["resultsPath"];
                    }
                    if (dataMap.ContainsKey("runDynamo"))
                    {
                        runDynamo = Convert.ToBoolean(dataMap["runDynamo"]);
                    }
                }

                if (string.IsNullOrEmpty(testAssembly))
                {
                    throw new Exception("Test assembly location must be specified in journal.");
                }

                if (string.IsNullOrEmpty(resultsPath))
                {
                    throw new Exception("You must supply a path for the results file.");
                }

                if (runDynamo)
                {
                    StartDynamo();
                }

                //http://stackoverflow.com/questions/2798561/how-to-run-nunit-from-my-code

                //Tests must be executed on the main thread in order to access the Revit API.
                //NUnit's SimpleTestRunner runs the tests on the main thread
                //http://stackoverflow.com/questions/16216011/nunit-c-run-specific-tests-through-coding?rq=1
                CoreExtensions.Host.InitializeService();
                var runner = new SimpleTestRunner();
                var builder = new TestSuiteBuilder();
                string testAssemblyLoc = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), testAssembly);

                var package = new TestPackage("DynamoTestFramework", new List<string>() {testAssemblyLoc});
                runner.Load(package);
                TestSuite suite = builder.Build(package);

                TestFixture fixture = null;
                FindFixtureByName(out fixture, suite, fixtureName);
                if (fixture == null)
                    throw new Exception(string.Format("Could not find fixture: {0}", fixtureName));

                InitializeResults();

                if (!canReadData)
                {
                    var currInvalid = Convert.ToInt16(resultsRoot.invalid);
                    resultsRoot.invalid = currInvalid + 1;
                    resultsRoot.testsuite.result = "Error";

                    throw new Exception("Journal file's data map contains no information about tests.");
                }

                //find or create a fixture
                var fixtureResult = FindOrCreateFixtureResults(dynamoResults, fixtureName);

                //convert the fixture's results array to a list
                var runningResults = fixtureResult.results.Items.ToList();

                //if the test name is not specified
                //run all tests in the fixture
                if (string.IsNullOrEmpty(testName) || testName == "None")
                {
                    var fixtureResults = RunFixture(fixture);
                    runningResults.AddRange(fixtureResults);
                }
                else
                {
                    var t = FindTestByName(fixture, testName);
                    if (t != null)
                    {
                        if (t is ParameterizedMethodSuite)
                        {
                            var paramSuite = t as ParameterizedMethodSuite;
                            foreach (var tInner in paramSuite.Tests)
                            {
                                if (tInner is TestMethod)
                                {
                                    runningResults.Add(RunTest((TestMethod)tInner));
                                }
                            }
                        }
                        else if (t is TestMethod)
                        {
                            runningResults.Add(RunTest((TestMethod)t));
                        }
                    }
                    else
                    {
                        //we have a journal file, but the specified test could not be found
                        var currInvalid = Convert.ToInt16(resultsRoot.invalid);
                        resultsRoot.invalid = currInvalid + 1;
                        resultsRoot.testsuite.result = "Error";
                    }
                }

                fixtureResult.results.Items = runningResults.ToArray();

                CalculateCaseTotalsOnSuite(fixtureResult);
                CalculateSweetTotalsOnOuterSweet(rootSuite);
                CalculateTotalsOnResultsRoot(resultsRoot);

                SaveResults();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                Console.WriteLine(ex.ToString());
                Console.WriteLine(ex.StackTrace);
                return Result.Failed;
            }

            return Result.Succeeded;
        }