Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
0
        public static int RunMain(string [] args)
        {
            var runOptions = RunOptions.Parse(args);

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

            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(-1);
            }

            var listener = new CommandLineTestEventListener(runOptions);
            var filter   = new AggregateTestFilter(runOptions.Filters);
            var results  = runner.Run(listener, filter, false, LoggingThreshold.Off);

            return(results.IsFailure ? 1 : 0);
        }
Ejemplo n.º 3
0
        }         // TestPerformance

        // ----------------------------------------------------------------------
        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);
        }         // TestPackage
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
0
        TestRunner SetupTest(IPNUnitServices services, TestConsoleAccess consoleAccess, TestLogInfo testLogInfo)
        {
            Directory.SetCurrentDirectory(Path.GetDirectoryName(mNUnitAssemblyPath));

            TestPackage package = new TestPackage(Path.GetFileName(mNUnitAssemblyPath));

            TestRunner result = new SimpleTestRunner();

            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

            bool testLoaded = result.Load(package);

            if (!testLoaded)
            {
                mLog.InfoFormat("Unable to locate test {0}", mPNUnitTestInfo.TestName);
                PNUnitTestResult testResult = PNUnitTestRunner.BuildError(
                    mPNUnitTestInfo, new Exception("Unable to locate tests"), consoleAccess,
                    testLogInfo);

                services.NotifyResult(
                    mPNUnitTestInfo.TestName, testResult);

                return(null);
            }

            InitPNUnitServices(
                mPNUnitTestInfo, result, services, consoleAccess, testLogInfo);

            return(result);
        }
Ejemplo n.º 6
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);
            }
        }
Ejemplo n.º 7
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));
            }
Ejemplo n.º 8
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));
        }
    }
Ejemplo n.º 9
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);
//                }
        }
Ejemplo n.º 10
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))
            {
                runner.Run(new NullListener(), TestFilter.Empty, false, LoggingThreshold.Error);
            }
        }
Ejemplo n.º 11
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.Debug);
                if (!result.IsSuccess)
                {
                    throw new Exception(result.Message);
                }
            }
        }
Ejemplo n.º 12
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();
            }
        }
Ejemplo n.º 13
0
        protected void Run()
        {
            var filter = ConstructFilter();

            var runner = new SimpleTestRunner();

            runner.Load(_testPackage);

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

            var outputFormatRaw = Request.QueryString["output"];

            if (outputFormatRaw == "xml")
            {
                OutputXml(result);
            }
            else
            {
                OutputVisual(result);
            }
        }
Ejemplo n.º 14
0
        protected void RunClick(object sender, EventArgs args)
        {
            var filter = ConstructFilter();

            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";
            }
        }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
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);
        }
Ejemplo n.º 17
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);
        }