Example #1
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";
            }
        }
Example #2
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);
        }
        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));
            }

            var setupMethods = fixture.GetSetUpMethods();

            foreach (var m in setupMethods)
            {
                Debug.WriteLine("Setup method: {0}", m.Name);
            }

            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);
        }
Example #4
0
 protected override TestRunner CreateRunner(int runnerID)
 {
     myRunner = new SimpleTestRunner(runnerID);
     return(myRunner);
 }
Example #5
0
    public static async Task <int> Main(string[] args)
    {
        Console.WriteLine($"ProcessorCount = {Environment.ProcessorCount}");

        Console.Write("Args: ");
        foreach (string arg in args)
        {
            Console.Write(arg);
        }
        Console.WriteLine(".");

        foreach (string arg in args.Where(a => a.StartsWith("testlib:")))
        {
            s_testLibs.Add(arg.Remove(0, "testlib:".Length));
        }
        bool verbose = args.Contains("--verbose");

        if (s_testLibs.Count < 1)
        {
            // Look for *.Tests.dll files if target test suites are not set via "testlib:" arguments
            s_testLibs = Directory.GetFiles(Environment.CurrentDirectory, "*.Tests.dll").ToList();
        }

        if (s_testLibs.Count < 1)
        {
            Console.WriteLine($"Test libs were not found (*.Tests.dll was not found in {Environment.CurrentDirectory})");
            return(-1);
        }

        Console.Write("Test libs: ");
        foreach (string testLib in s_testLibs)
        {
            Console.WriteLine(testLib);
        }
        Console.WriteLine(".");
        s_MainTestName = Path.GetFileNameWithoutExtension(s_testLibs[0]);

        mono_ios_set_summary($"Starting tests...");
        var simpleTestRunner = new SimpleTestRunner(verbose);

        simpleTestRunner.TestStarted += (target, e) =>
        {
            mono_ios_append_output($"[STARTING] {e}\n");
        };

        int failed = 0, passed = 0, skipped = 0;

        simpleTestRunner.TestCompleted += (target, e) =>
        {
            if (e.Item2 == TestResult.Passed)
            {
                passed++;
            }
            else if (e.Item2 == TestResult.Failed)
            {
                failed++;
            }
            else if (e.Item2 == TestResult.Skipped)
            {
                skipped++;
            }
            mono_ios_set_summary($"{s_MainTestName}\nPassed:{passed}, Failed: {failed}, Skipped:{skipped}");
        };

        await simpleTestRunner.RunAsync();

        mono_ios_append_output($"\nDone.\n");
        Console.WriteLine("----- Done -----");
        return(0);
    }
		protected override TestRunner CreateRunner( int runnerID )
		{
			myRunner = new SimpleTestRunner( runnerID );
			return myRunner;
		}
Example #7
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);
        }
Example #8
0
        TestRunner SetupTest(
            PNUnitTestInfo testInfo,
            IPNUnitServices services,
            TestConsoleAccess consoleAccess,
            TestLogInfo testLogInfo,
            ITestConsoleAccess extraConsoleAccess)
        {
            TestRunner result;
            bool       testAssemblyLoaded;

            if (mPreloader == null)
            {
                result = new SimpleTestRunner();

                int ini = Environment.TickCount;

                string fullAssemblyPath = Path.GetFullPath(
                    Path.Combine(mPathToAssemblies, testInfo.AssemblyName));

                mLog.DebugFormat("Loading test assembly from {0}", fullAssemblyPath);

                testAssemblyLoaded = MakeTest(result, fullAssemblyPath);

                mLog.DebugFormat("Load test assembly {0} ms", Environment.TickCount - ini);
            }
            else
            {
                //if (!AssemblyPreload.CanUsePreload(testInfo.AssemblyName))
                //{
                //    throw new Exception(
                //        "The preloaded and the target assembly don't match!!");
                //}

                result             = mPreloader.TestRunner;
                testAssemblyLoaded = mPreloader.TestAssemblyLoaded;
            }

            if (!testAssemblyLoaded)
            {
                mLog.InfoFormat("Unable to load test assembly {0} for test {1}",
                                testInfo.AssemblyName,
                                testInfo.TestName);

                PNUnitTestResult testResult = BuildError(
                    testInfo, new Exception("Unable to locate tests"),
                    consoleAccess, testLogInfo);

                services.NotifyResult(
                    testInfo.TestName, testResult);

                return(null);
            }

            mLog.Debug("Test loaded, going to set CurrentDirectory");

            Directory.SetCurrentDirectory(mPathToAssemblies);

            mLog.Debug("Creating PNUnit services");

            CreatePNUnitServices(testInfo, result, services, consoleAccess,
                                 testLogInfo, extraConsoleAccess);

            return(result);
        }