protected 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
            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));
            }
        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);
        }
        private IEnumerable <TestData> GetGallioTestcases(TestFrameworkLogger frameworkLogger, IEnumerable <string> sources)
        {
            try
            {
                var testFrameworkManager = RuntimeAccessor.ServiceLocator.Resolve <ITestFrameworkManager>();
                var loader = new ReflectionOnlyAssemblyLoader();

                IList <ICodeElementInfo> assemblyInfos = sources.Select(source => LoadAssembly(source, loader)).Where(assembly => assembly != null).ToList();

                var testFrameworkSelector = new TestFrameworkSelector()
                {
                    Filter = testFrameworkHandle => testFrameworkHandle.Id != "MSTestAdapter.TestFramework" || testFrameworkHandle.Id != "NUnitAdapter.TestFramework",

                    FallbackMode = TestFrameworkFallbackMode.Approximate
                };

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

                var             tests           = new List <TestData>();
                MessageConsumer messageConsumer = new MessageConsumer()
                                                  .Handle <TestDiscoveredMessage>(message =>
                {
                    if (message.Test.IsTestCase)
                    {
                        tests.Add((message.Test));
                    }
                })
                                                  .Handle <AnnotationDiscoveredMessage>(message => message.Annotation.Log(frameworkLogger, true));

                driver.Describe(loader.ReflectionPolicy, assemblyInfos,
                                testExplorationOptions, messageConsumer, NullProgressMonitor.CreateInstance());

                bool reset = ResetCollectionForExposedTests(tests);

                if (reset)
                {
                    tests = null;
                }

                return(tests);
            }
            catch (Exception ex)
            {
                frameworkLogger.Log(LogSeverity.Error, "Gallio failed to load tests", ex);

                return(null);
            }
        }
示例#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
        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);
        }
示例#7
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));
            }