public TestFilter ConvertTfsFilterToNUnitFilter(TfsTestFilter tfsFilter, List <TestCase> loadedTestCases)
        {
            var filteredTestCases = tfsFilter.CheckFilter(loadedTestCases);
            var testCases         = filteredTestCases as TestCase[] ?? filteredTestCases.ToArray();

            //TestLog.Info(string.Format("TFS Filter detected: LoadedTestCases {0}, Filterered Test Cases {1}", loadedTestCases.Count, testCases.Count()));
            return(MakeTestFilter(testCases));
        }
Example #2
0
        private void RunAssembly(string assemblyName, IFrameworkHandle frameworkHandle)
        {
#if LAUNCHDEBUGGER
            if (!Debugger.IsAttached)
            {
                Debugger.Launch();
            }
#endif
            _testRunner = GetRunnerFor(assemblyName);

            try
            {
                var loadResult = _testRunner.Explore(TestFilter.Empty);

                if (loadResult.Name == "test-run")
                {
                    loadResult = loadResult.FirstChild;
                }

                if (loadResult.GetAttribute("runstate") == "Runnable")
                {
                    TestLog.SendInformationalMessage(string.Format("Loading tests from {0}", assemblyName));

                    var nunitTestCases = loadResult.SelectNodes("//test-case");

                    using (var testConverter = new TestConverter(TestLog, assemblyName))
                    {
                        var loadedTestCases = new List <TestCase>();

                        // As a side effect of calling TestConverter.ConvertTestCase,
                        // the converter's cache of all test cases is populated as well.
                        // All future calls to convert a test case may now use the cache.
                        foreach (XmlNode testNode in nunitTestCases)
                        {
                            loadedTestCases.Add(testConverter.ConvertTestCase(testNode));
                        }

                        // If we have a TFS Filter, convert it to an nunit filter
                        if (_tfsFilter != null && _tfsFilter.HasTfsFilterValue)
                        {
                            var filteredTestCases = _tfsFilter.CheckFilter(loadedTestCases);
                            var testCases         = filteredTestCases as TestCase[] ?? filteredTestCases.ToArray();
                            TestLog.SendInformationalMessage(string.Format("TFS Filter detected: LoadedTestCases {0}, Filterered Test Cases {1}", loadedTestCases.Count, testCases.Count()));
                            _nunitFilter = MakeTestFilter(testCases);
                        }

                        using (var listener = new NUnitEventListener(frameworkHandle, testConverter))
                        {
                            try
                            {
                                _testRunner.Run(listener, _nunitFilter);
                            }
                            catch (NullReferenceException)
                            {
                                // this happens during the run when CancelRun is called.
                                TestLog.SendDebugMessage("Nullref caught");
                            }
                        }
                    }
                }
                else
                {
                    TestLog.NUnitLoadError(assemblyName);
                }
            }
            catch (BadImageFormatException)
            {
                // we skip the native c++ binaries that we don't support.
                TestLog.AssemblyNotSupportedWarning(assemblyName);
            }
            catch (System.IO.FileNotFoundException ex)
            {
                // Probably from the GetExportedTypes in NUnit.core, attempting to find an assembly, not a problem if it is not NUnit here
                TestLog.DependentAssemblyNotFoundWarning(ex.FileName, assemblyName);
            }
            catch (Exception ex)
            {
                if (ex is TargetInvocationException)
                {
                    ex = ex.InnerException;
                }
                TestLog.SendErrorMessage("Exception thrown executing tests in " + assemblyName, ex);
            }
            _testRunner.Dispose();
        }