예제 #1
0
        /// <summary>
        /// Called by the VisualStudio IDE when selected tests are to be run. Never called from TFS Build.
        /// </summary>
        /// <param name="tests">The tests to be run</param>
        /// <param name="runContext">The RunContext</param>
        /// <param name="frameworkHandle">The FrameworkHandle</param>
        public void RunTests(IEnumerable <TestCase> tests, IRunContext runContext, IFrameworkHandle frameworkHandle)
        {
#if LAUNCHDEBUGGER
            if (!Debugger.IsAttached)
            {
                Debugger.Launch();
            }
#endif
            Initialize(runContext, frameworkHandle);

            var assemblyGroups = tests.GroupBy(tc => tc.Source);
            foreach (var assemblyGroup in assemblyGroups)
            {
                var assemblyName = assemblyGroup.Key;
                if (Debugger.IsAttached)
                {
                    TestLog.Info("Debugging selected tests in " + assemblyName);
                }
                else
                {
                    TestLog.Info("Running selected tests in " + assemblyName);
                }

                var filterBuilder = new NUnitTestFilterBuilder(TestEngine.Services.GetService <ITestFilterService>());
                var filter        = filterBuilder.MakeTestFilter(assemblyGroup);

                RunAssembly(assemblyName, filter);
            }

            TestLog.Info(string.Format("NUnit Adapter {0}: Test execution complete", AdapterVersion));
            Unload();
        }
예제 #2
0
        /// <summary>
        /// Called by the VisualStudio IDE when selected tests are to be run. Never called from TFS Build.
        /// </summary>
        /// <param name="tests">The tests to be run</param>
        /// <param name="runContext">The RunContext</param>
        /// <param name="frameworkHandle">The FrameworkHandle</param>
        public void RunTests(IEnumerable <TestCase> tests, IRunContext runContext, IFrameworkHandle frameworkHandle)
        {
#if LAUNCHDEBUGGER
            if (!Debugger.IsAttached)
            {
                Debugger.Launch();
            }
#endif
            Initialize(runContext, frameworkHandle);

            var assemblyGroups = tests.GroupBy(tc => tc.Source);
            if (Settings.InProcDataCollectorsAvailable && assemblyGroups.Count() > 1)
            {
                TestLog.Error("Failed to run tests for multiple assemblies when InProcDataCollectors specified in run configuration.");
                Unload();
                return;
            }

            foreach (var assemblyGroup in assemblyGroups)
            {
                var assemblyName = assemblyGroup.Key;
                if (Debugger.IsAttached)
                {
                    TestLog.Info("Debugging selected tests in " + assemblyName);
                }
                else
                {
                    TestLog.Info("Running selected tests in " + assemblyName);
                }

                var filterBuilder = new NUnitTestFilterBuilder(TestEngine.Services.GetService <ITestFilterService>());
                var filter        = filterBuilder.MakeTestFilter(assemblyGroup);

                RunAssembly(assemblyName, filter);
            }

            TestLog.Info(string.Format("NUnit Adapter {0}: Test execution complete", AdapterVersion));
            Unload();
        }
예제 #3
0
        private void RunAssembly(string assemblyName, TestFilter filter)
        {
#if LAUNCHDEBUGGER
            if (!Debugger.IsAttached)
            {
                Debugger.Launch();
            }
#endif
            _activeRunner = GetRunnerFor(assemblyName);

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

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

                if (loadResult.GetAttribute("runstate") == "Runnable")
                {
                    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));
                        }

                        TestLog.Info(string.Format("NUnit3TestExecutor converted {0} of {1} NUnit test cases", loadedTestCases.Count, nunitTestCases.Count));

                        // If we have a TFS Filter, convert it to an nunit filter
                        if (TfsFilter != null && !TfsFilter.IsEmpty)
                        {
                            // NOTE This overwrites filter used in call
                            var filterBuilder = new NUnitTestFilterBuilder(TestEngine.Services.GetService <ITestFilterService>());
                            filter = filterBuilder.ConvertTfsFilterToNUnitFilter(TfsFilter, loadedTestCases);
                        }

                        if (filter == NUnitTestFilterBuilder.NoTestsFound)
                        {
                            TestLog.Info("Skipping assembly - no matching test cases found");
                            return;
                        }

                        using (var listener = new NUnitEventListener(FrameworkHandle, testConverter))
                        {
                            try
                            {
                                _activeRunner.Run(listener, filter);
                            }
                            catch (NullReferenceException)
                            {
                                // this happens during the run when CancelRun is called.
                                TestLog.Debug("Nullref caught");
                            }
                        }
                    }
                }
                else
                {
                    TestLog.Info("NUnit failed to load " + assemblyName);
                }
            }
            catch (BadImageFormatException)
            {
                // we skip the native c++ binaries that we don't support.
                TestLog.Warning("Assembly not supported: " + 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.Warning("Dependent Assembly " + ex.FileName + " of " + assemblyName + " not found. Can be ignored if not a NUnit project.");
            }
            catch (Exception ex)
            {
                if (ex is TargetInvocationException)
                {
                    ex = ex.InnerException;
                }
                TestLog.Error("Exception thrown executing tests in " + assemblyName, ex);
            }

            _activeRunner.Dispose();
            _activeRunner = null;
        }
예제 #4
0
        /// <summary>
        /// Called by the VisualStudio IDE when selected tests are to be run. Never called from TFS Build.
        /// </summary>
        /// <param name="tests">The tests to be run</param>
        /// <param name="runContext">The RunContext</param>
        /// <param name="frameworkHandle">The FrameworkHandle</param>
        public void RunTests(IEnumerable<TestCase> tests, IRunContext runContext, IFrameworkHandle frameworkHandle)
        {
#if LAUNCHDEBUGGER
            if (!Debugger.IsAttached)
                Debugger.Launch();
#endif
            Initialize(runContext, frameworkHandle);

            var assemblyGroups = tests.GroupBy(tc => tc.Source);
            foreach (var assemblyGroup in assemblyGroups)
            {
                var assemblyName = assemblyGroup.Key;
                if (Debugger.IsAttached)
                    TestLog.Info("Debugging selected tests in " + assemblyName);
                else
                    TestLog.Info("Running selected tests in " + assemblyName);

                var filterBuilder = new NUnitTestFilterBuilder(TestEngine.Services.GetService<ITestFilterService>());
                var filter = filterBuilder.MakeTestFilter(assemblyGroup);

                RunAssembly(assemblyName, filter);
            }

            TestLog.Info(string.Format("NUnit Adapter {0}: Test execution complete", AdapterVersion));
            Unload();
        }
예제 #5
0
        private void RunAssembly(string assemblyName, TestFilter filter)
        {
#if LAUNCHDEBUGGER
            if (!Debugger.IsAttached)
                Debugger.Launch();
#endif
            _activeRunner = GetRunnerFor(assemblyName);

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

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

                if (loadResult.GetAttribute("runstate") == "Runnable")
                {
                    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));

                        TestLog.Info(string.Format("NUnit3TestExecutor converted {0} of {1} NUnit test cases", loadedTestCases.Count, nunitTestCases.Count));

                        // If we have a TFS Filter, convert it to an nunit filter
                        if (TfsFilter != null && !TfsFilter.IsEmpty)
                        {
                            // NOTE This overwrites filter used in call
                            var filterBuilder = new NUnitTestFilterBuilder(TestEngine.Services.GetService<ITestFilterService>());
                            filter = filterBuilder.ConvertTfsFilterToNUnitFilter(TfsFilter, loadedTestCases);
                        }

                        if (filter == NUnitTestFilterBuilder.NoTestsFound)
                        {
                            TestLog.Info("Skipping assembly - no matching test cases found");
                            return;
                        }

                        using (var listener = new NUnitEventListener(FrameworkHandle, testConverter))
                        {
                            try
                            {
                                _activeRunner.Run(listener, filter);
                            }
                            catch (NullReferenceException)
                            {
                                // this happens during the run when CancelRun is called.
                                TestLog.Debug("Nullref caught");
                            }
                        }
                    }
                }
                else
                    TestLog.Info("NUnit failed to load " + assemblyName);
            }
            catch (BadImageFormatException)
            {
                // we skip the native c++ binaries that we don't support.
                TestLog.Warning("Assembly not supported: " + 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.Warning("Dependent Assembly " + ex.FileName + " of " + assemblyName + " not found. Can be ignored if not a NUnit project.");
            }
            catch (Exception ex)
            {
                if (ex is TargetInvocationException)
                    ex = ex.InnerException;
                TestLog.Error("Exception thrown executing tests in " + assemblyName, ex);
            }

            _activeRunner.Dispose();
            _activeRunner = null;
        }