TestModel PopulateTestTree(Assembly assembly)
    {
      TestModel testModel = new TestModel();

      var testFrameworkManager = RuntimeAccessor.ServiceLocator.Resolve<ITestFrameworkManager>();
      var logger = new MarkupStreamLogger(TestLog.Default);

      var testFrameworkSelector = new TestFrameworkSelector()
      {
        Filter = testFrameworkHandle => testFrameworkHandle.Id == TestFrameworkHandle.Id,
        FallbackMode = TestFrameworkFallbackMode.Strict
      };

      ITestDriver testDriver = testFrameworkManager.GetTestDriver(testFrameworkSelector, logger);

      var testIsolationProvider = (ITestIsolationProvider)RuntimeAccessor.ServiceLocator.ResolveByComponentId("Gallio.LocalTestIsolationProvider");
      var testIsolationOptions = new TestIsolationOptions();
      using (ITestIsolationContext testIsolationContext = testIsolationProvider.CreateContext(testIsolationOptions, logger))
      {
        var testPackage = new TestPackage();
        testPackage.AddFile(new FileInfo(AssemblyUtils.GetFriendlyAssemblyCodeBase(assembly)));
        var testExplorationOptions = new TestExplorationOptions();

        var messageSink = TestModelSerializer.CreateMessageSinkToPopulateTestModel(testModel);

        new LogProgressMonitorProvider(logger).Run(progressMonitor =>
        {
          testDriver.Explore(testIsolationContext, testPackage, testExplorationOptions,
            messageSink, progressMonitor);
        });
      }

      return testModel;
    }
예제 #2
0
        /// <summary>
        /// Creates a test framework selector based on the package properties.
        /// </summary>
        /// <remarks>
        /// Considers the <see cref="TestFrameworkOptions" />, <see cref="TestFrameworkFallbackMode" />,
        /// and <see cref="ExcludedTestFrameworkIds" />.
        /// </remarks>
        /// <returns>The test framework selector.</returns>
        public TestFrameworkSelector CreateTestFrameworkSelector()
        {
            var selector = new TestFrameworkSelector()
            {
                Filter       = testFrameworkHandle => !excludedTestFrameworkIds.Contains(testFrameworkHandle.Id),
                FallbackMode = testFrameworkFallbackMode
            };

            if (isTestFrameworkOptionsSpecified)
            {
                selector.Options = testFrameworkOptions;
            }

            return(selector);
        }
        /// <inheritdoc />
        public ITestDriver GetTestDriver(TestFrameworkSelector selector, ILogger logger)
        {
            if (selector == null)
            {
                throw new ArgumentNullException("selector");
            }
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }

            return(new FilteredTestDriver(this,
                                          GetFilteredTestFrameworkHandlesWithoutFallback(selector.Filter),
                                          selector.FallbackMode, selector.Options, logger));
        }
예제 #4
0
        public Runner()
        {
            // Create a runtime setup.
            // There are a few things you can tweak here if you need.
            _setup = new Gallio.Runtime.RuntimeSetup();
            //_setup.RuntimePath = @"C:\Users\ack\bin\GallioBundle-3.2.750.0\bin"; // @"C:\Users\ack\bin\Gallio2"; //Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); //@"C:\Users\ack\bin\GallioBundle-3.2.750.0\bin";
            var binPath = new BinPathLocator().Locate();
            _isInitialized = File.Exists(Path.Combine(binPath, "Gallio.dll"));
            if (!_isInitialized)
                return;
            _setup.RuntimePath = binPath; //@"C:\Users\ack\src\AutoTest.Net\lib\Gallio";

            // Create a logger.
            // You can use the NullLogger but you will probably want a wrapper around your own ILogger thingy.
            _logger = Gallio.Runtime.Logging.NullLogger.Instance;

            // Initialize the runtime.
            // You only do this once.
            lock (_gallioLock)
            {
                if (!_runtimeInitialized)
                {
                    RuntimeBootstrap.Initialize(_setup, _logger);
                    _runtimeInitialized = true;
                }
            }

            // Create a test framework selector.
            // This is used by Gallio to filter the set of frameworks it will support.
            // You can set a predicate Filter here.  I've hardcoded MbUnit here but you could leave the filter out and set it to null.
            // The fallback mode tells Gallio what to do if it does not recognize the test framework associated with the test assembly.
            // Strict means don't do anything.  You might want to use Default or Approximate.  See docs.
            // You can also set options, probably don't care.
            var testFrameworkSelector = new TestFrameworkSelector()
            {
                Filter = testFrameworkHandle => testFrameworkHandle.Id == "MbUnit.TestFramework",
                FallbackMode = TestFrameworkFallbackMode.Strict
            };

            // Now we need to get a suitably configured ITestDriver...
            var testFrameworkManager = RuntimeAccessor.ServiceLocator.Resolve<ITestFrameworkManager>();
            _testDriver = testFrameworkManager.GetTestDriver(testFrameworkSelector, _logger);
        }
예제 #5
0
        public override ICollection Load(string location, ProjectData projectData, IWarningHandler warningHandler)
        {
            // Skip loading if the extension is not fully initalized unless we are not
            // running in Visual Studio (because we are running in MSTest instead).
            if (!TipShellExtension.IsInitialized && ShellEnvironment.IsRunningInVisualStudio)
                return EmptyArray<TestElement>.Instance;

            // Explore the tests.
            ITestFrameworkManager testFrameworkManager = RuntimeAccessor.ServiceLocator.Resolve<ITestFrameworkManager>();
            WarningLogger logger = new WarningLogger(warningHandler);

            ReflectionOnlyAssemblyLoader loader = new ReflectionOnlyAssemblyLoader();
            loader.AddHintDirectory(Path.GetDirectoryName(location));

            IAssemblyInfo assembly = loader.ReflectionPolicy.LoadAssemblyFrom(location);

            var testFrameworkSelector = new TestFrameworkSelector()
            {
                Filter = testFrameworkHandle => testFrameworkHandle.Id != "MSTestAdapter.TestFramework",
                FallbackMode = TestFrameworkFallbackMode.Approximate
            };

            ITestDriver driver = testFrameworkManager.GetTestDriver(testFrameworkSelector, logger);
            TestExplorationOptions testExplorationOptions = new TestExplorationOptions();

            ArrayList tests = new ArrayList();
            MessageConsumer messageConsumer = new MessageConsumer()
                .Handle<TestDiscoveredMessage>(message =>
                {
                    if (message.Test.IsTestCase)
                        tests.Add(GallioTestElementFactory.CreateTestElement(message.Test, location, projectData));
                })
                .Handle<AnnotationDiscoveredMessage>(message =>
                {
                    message.Annotation.Log(logger, true);
                });

            driver.Describe(loader.ReflectionPolicy, new ICodeElementInfo[] { assembly },
                testExplorationOptions, messageConsumer, NullProgressMonitor.CreateInstance());

            return tests;
        }
예제 #6
0
            private ITestDriver CreateTestDriver()
            {
                var excludedTestFrameworkIds = new List<string>();
                foreach (IUnitTestProvider provider in UnitTestManager.GetInstance(SolutionManager.Instance.CurrentSolution).GetEnabledProviders())
                {
                    IList<string> frameworkIds;
                    if (IncompatibleProviders.TryGetValue(provider.ID, out frameworkIds))
                        excludedTestFrameworkIds.AddRange(frameworkIds);
                }

                var testFrameworkSelector = new TestFrameworkSelector()
                {
                    Filter = testFrameworkHandle => !excludedTestFrameworkIds.Contains(testFrameworkHandle.Id),
                    FallbackMode = TestFrameworkFallbackMode.Approximate
                };
                return testFrameworkManager.GetTestDriver(testFrameworkSelector, logger);
            }
        private static ITestDriver GetTestDriver(ILogger frameworkLogger)
        {
            var testFrameworkManager = RuntimeAccessor.ServiceLocator.Resolve<ITestFrameworkManager>();

            var testFrameworkSelector = new TestFrameworkSelector
            {
                Filter = testFrameworkHandle => NotMsTestOrNunit(testFrameworkHandle.Id),
                FallbackMode = TestFrameworkFallbackMode.Approximate
            };

            var testDriver = testFrameworkManager.GetTestDriver(testFrameworkSelector, frameworkLogger);
            return testDriver;
        }
예제 #8
0
        /// <summary>
        /// Creates a test framework selector based on the package properties.
        /// </summary>
        /// <remarks>
        /// Considers the <see cref="TestFrameworkOptions" />, <see cref="TestFrameworkFallbackMode" />,
        /// and <see cref="ExcludedTestFrameworkIds" />.
        /// </remarks>
        /// <returns>The test framework selector.</returns>
        public TestFrameworkSelector CreateTestFrameworkSelector()
        {
            var selector = new TestFrameworkSelector()
            {
                Filter = testFrameworkHandle => !excludedTestFrameworkIds.Contains(testFrameworkHandle.Id),
                FallbackMode = testFrameworkFallbackMode
            };

            if (isTestFrameworkOptionsSpecified)
                selector.Options = testFrameworkOptions;

            return selector;
        }
예제 #9
0
            private ITestDriver CreateTestDriver()
            {
                var excludedTestFrameworkIds = new List<string>();

#if RESHARPER_60
				var unitTestManager = UnitTestManager.GetInstance(provider.Solution);
				var unitTestProviders = unitTestManager.GetEnabledProviders();
#else
            	var unitTestProviders = provider.UnitTestProvidersManager.GetEnabledProviders();
#endif
            	foreach (var testProvider in unitTestProviders)
                {
                    IList<string> frameworkIds;
                    if (IncompatibleProviders.TryGetValue(testProvider.ID, out frameworkIds))
                        excludedTestFrameworkIds.AddRange(frameworkIds);
                }

                var testFrameworkSelector = new TestFrameworkSelector
                                                {
                    Filter = testFrameworkHandle => !excludedTestFrameworkIds.Contains(testFrameworkHandle.Id),
                    FallbackMode = TestFrameworkFallbackMode.Approximate
                };
                return testFrameworkManager.GetTestDriver(testFrameworkSelector, logger);
            }
        /// <inheritdoc />
        public IMultiMap <TestFrameworkSelection, ICodeElementInfo> SelectTestFrameworksForCodeElements(TestFrameworkSelector selector, ICollection <ICodeElementInfo> codeElements)
        {
            if (selector == null)
            {
                throw new ArgumentNullException("selector");
            }
            if (codeElements == null || codeElements.Contains(null))
            {
                throw new ArgumentNullException("codeElements");
            }

            return(SelectTestFrameworksForCodeElementsImpl(GetFilteredTestFrameworkHandlesWithoutFallback(selector.Filter),
                                                           selector.FallbackMode, selector.Options, codeElements));
        }
        /// <inheritdoc />
        public IMultiMap <TestFrameworkSelection, FileInfo> SelectTestFrameworksForFiles(TestFrameworkSelector selector, ICollection <FileInfo> files)
        {
            if (selector == null)
            {
                throw new ArgumentNullException("selector");
            }
            if (files == null || files.Contains(null))
            {
                throw new ArgumentNullException("files");
            }

            return(SelectTestFrameworksForFilesImpl(GetFilteredTestFrameworkHandlesWithoutFallback(selector.Filter),
                                                    selector.FallbackMode, selector.Options, files));
        }