/// <summary>
 /// Creates a sample runner.
 /// </summary>
 public SampleRunner()
 {
     testPackage = new TestPackage();
     filters = new List<Filter<ITestDescriptor>>();
     TestRunnerFactoryName = StandardTestRunnerFactoryNames.Local;
     testRunnerOptions = new TestRunnerOptions();
 }
        protected override void ConfigureHostSetup(HostSetup hostSetup, TestPackage testPackage, string assemblyPath, AssemblyMetadata assemblyMetadata)
        {
            base.ConfigureHostSetup(hostSetup, testPackage, assemblyPath, assemblyMetadata);

            // csUnit always creates its own AppDomain with shadow copy enabled so we do not need this.
            hostSetup.ShadowCopy = false;
        }
        public void Execute_should_reload_the_test_package()
        {
            var testPackage = new TestPackage();
            projectController.Stub(pc => pc.TestPackage).Return(testPackage);

            loadPackageCommand.Execute(progressMonitor);

            testController.AssertWasCalled(tc => tc.SetTestPackage(testPackage));
        }
 /// <summary>
 /// Creates an empty test project.
 /// </summary>
 public TestProject()
 {
     testPackage = new TestPackage();
     testFilters = new List<FilterInfo>();
     testRunnerExtensions = new List<ITestRunnerExtension>();
     testRunnerExtensionSpecifications = new List<string>();
     reportNameFormat = DefaultReportNameFormat;
     reportDirectory = DefaultReportDirectoryRelativePath;
     testRunnerFactoryName = DefaultTestRunnerFactoryName;
     ReportArchive = ReportArchive.Normal;
 }
        protected override void ConfigureHostSetup(HostSetup hostSetup, TestPackage testPackage,
            string assemblyPath, AssemblyMetadata assemblyMetadata)
        {
            base.ConfigureHostSetup(hostSetup, testPackage, assemblyPath, assemblyMetadata);

            if (hostSetup.ProcessorArchitecture == ProcessorArchitecture.Amd64
                || hostSetup.ProcessorArchitecture == ProcessorArchitecture.IA64)
                throw new ModelException("Cannot run MSTest tests compiled for 64bit because MSTest.exe throws exceptions when run without isolation as a 64bit process.");

            hostSetup.ProcessorArchitecture = ProcessorArchitecture.X86;
        }
 public void SetUp()
 {
     logger = MockRepository.GenerateStub<ILogger>();
     driver = new IronRubyTestDriver(logger);
     var testIsolationProvider = (ITestIsolationProvider)RuntimeAccessor.ServiceLocator.ResolveByComponentId("Gallio.LocalTestIsolationProvider");
     testIsolationContext = testIsolationProvider.CreateContext(new TestIsolationOptions(), logger);
     testPackage = new TestPackage();
     testExplorationOptions = new TestExplorationOptions();
     testExecutionOptions = new TestExecutionOptions();
     messageSink = MockRepository.GenerateStub<IMessageSink>();
     progressMonitor = NullProgressMonitor.CreateInstance();
 }
        /// <summary>
        /// Initializes the event arguments.
        /// </summary>
        /// <param name="testPackage">The test package configuration.</param>
        /// <param name="testExplorationOptions">The test exploration options.</param>
        /// <param name="reportLockBox">The report lock-box which may be used to access the report asynchronously during execution.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="testPackage"/>
        /// or <paramref name="testExplorationOptions"/> is null.</exception>
        public ExploreStartedEventArgs(TestPackage testPackage, TestExplorationOptions testExplorationOptions,
            LockBox<Report> reportLockBox)
        {
            if (testPackage == null)
                throw new ArgumentNullException("testPackage");
            if (testExplorationOptions == null)
                throw new ArgumentNullException("testExplorationOptions");

            this.testPackage = testPackage;
            this.testExplorationOptions = testExplorationOptions;
            this.reportLockBox = reportLockBox;
        }
        public void Execute_should_reload_the_test_package()
        {
            var testController = MockRepository.GenerateStub<ITestController>();
            var projectController = MockRepository.GenerateStub<IProjectController>();
            var removeAllFilesCommand = new RemoveAllFilesCommand(testController, projectController);
            var progressMonitor = MockProgressMonitor.Instance;
            var testPackage = new TestPackage();
            projectController.Stub(pc => pc.TestPackage).Return(testPackage);

            removeAllFilesCommand.Execute(progressMonitor);

            testController.AssertWasCalled(tc => tc.SetTestPackage(testPackage));
        }
        /// <inheritdoc />
        public void Explore(ITestIsolationContext testIsolationContext, TestPackage testPackage, TestExplorationOptions testExplorationOptions,
            IMessageSink messageSink, IProgressMonitor progressMonitor)
        {
            if (testIsolationContext == null)
                throw new ArgumentNullException("testIsolationContext");
            if (testPackage == null)
                throw new ArgumentNullException("testPackage");
            if (testExplorationOptions == null)
                throw new ArgumentNullException("testExplorationOptions");
            if (messageSink == null)
                throw new ArgumentNullException("messageSink");
            if (progressMonitor == null)
                throw new ArgumentNullException("progressMonitor");

            ExploreImpl(testIsolationContext, testPackage, testExplorationOptions, messageSink, progressMonitor);
        }
 protected override void ExploreImpl(ITestIsolationContext testIsolationContext, TestPackage testPackage, TestExplorationOptions testExplorationOptions, IMessageSink messageSink, IProgressMonitor progressMonitor)
 {
     using (progressMonitor.BeginTask("Exploring tests.", 1))
     {
         ForEachDriver(testFrameworkManager.SelectTestFrameworksForFilesImpl(
                           testFrameworkHandles, testFrameworkFallbackMode, testFrameworkOptions, testPackage.Files),
                       (driver, items, driverCount) =>
         {
             TestPackage testPackageForDriver = CreateTestPackageWithFiles(testPackage, items);
             driver.Explore(testIsolationContext, testPackageForDriver, testExplorationOptions, messageSink,
                            progressMonitor.CreateSubProgressMonitor(1.0 / driverCount));
             return(false);
         });
     }
 }
Exemple #11
0
 /// <summary>
 /// Configures the host setup prior to the initialization of the script runtime.
 /// </summary>
 /// <remarks>
 /// <para>
 /// The default implementation does nothing.  Subclasses may override this method
 /// to customize the host setup.
 /// </para>
 /// </remarks>
 /// <param name="hostSetup">The host setup, not null.</param>
 /// <param name="testPackage">The test package, not null.</param>
 /// <param name="assemblyPath">The assembly path, not null.</param>
 /// <param name="assemblyMetadata">The assembly metadata, not null.</param>
 protected virtual void ConfigureHostSetup(HostSetup hostSetup, TestPackage testPackage, string assemblyPath, AssemblyMetadata assemblyMetadata)
 {
 }
 private static List<TestData> FindTests(TestPackage testPackage, ITestRunner runner)
 {
     var options = new TestExplorationOptions();
     testPackage.AddExcludedTestFrameworkId(MsTestFrameworkHandleId);
     testPackage.AddExcludedTestFrameworkId(NUnitTestFrameworkHandleId);
     var result = runner.Explore(testPackage, options, new ObservableProgressMonitor());
     var tests = result.TestModel.AllTests.Where(t => t.IsTestCase).ToList();
     return tests;
 }
        public void Run_Test()
        {
            var progressMonitor = MockProgressMonitor.Instance;
            var filter = new FilterSet<ITestDescriptor>(new NoneFilter<ITestDescriptor>());
            filterService.Stub(fs => fs.GenerateFilterSetFromSelectedTests()).Return(filter);
            optionsController.Stub(oc => oc.TestRunnerExtensions).Return(new BindingList<string>(new List<string>()));
            StubTestRunnerFactory();
            var testPackage = new TestPackage();
            testPackage.AddFile(new FileInfo("test"));

            testController.SetTestPackage(testPackage);
            testController.Run(false, progressMonitor, new List<string>());

            testRunner.AssertWasCalled(tr => tr.Run(Arg<TestPackage>.Matches(tpc => tpc.Files.Count == 1), 
                Arg<TestExplorationOptions>.Is.Anything, 
                Arg<TestExecutionOptions>.Matches(teo => ((teo.FilterSet == filter) && !teo.ExactFilter)), 
                Arg.Is(progressMonitor)));
        }
 protected override FileInfo GetTestDriverScriptFile(TestPackage testPackage)
 {
     return new FileInfo(@"..\Scripts\IronRuby\sample_driver.rb");
 }
 /// <summary>
 /// Creates a host setup for a particular assembly within a test package.
 /// </summary>
 /// <param name="testPackage">The test package, not null.</param>
 /// <param name="assemblyPath">The assembly path, not null.</param>
 /// <param name="assemblyMetadata">The assembly metadata, not null.</param>
 /// <returns>The host setup setup.</returns>
 protected HostSetup CreateHostSetup(TestPackage testPackage, string assemblyPath, AssemblyMetadata assemblyMetadata)
 {
     HostSetup hostSetup = testPackage.CreateHostSetup();
     ConfigureHostSetupForAssembly(hostSetup, assemblyPath, assemblyMetadata);
     ConfigureHostSetup(hostSetup, testPackage, assemblyPath, assemblyMetadata);
     return hostSetup;
 }
 /// <summary>
 /// Configures the host setup prior to the initialization of the script runtime.
 /// </summary>
 /// <remarks>
 /// <para>
 /// The default implementation does nothing.  Subclasses may override this method
 /// to customize the host setup.
 /// </para>
 /// </remarks>
 /// <param name="hostSetup">The host setup, not null.</param>
 /// <param name="testPackage">The test package, not null.</param>
 /// <param name="assemblyPath">The assembly path, not null.</param>
 /// <param name="assemblyMetadata">The assembly metadata, not null.</param>
 protected virtual void ConfigureHostSetup(HostSetup hostSetup, TestPackage testPackage, string assemblyPath, AssemblyMetadata assemblyMetadata)
 {
 }
        private void ExploreOrRunAssembly(ITestIsolationContext testIsolationContext, TestPackage testPackage, TestExplorationOptions testExplorationOptions,
            TestExecutionOptions testExecutionOptions, RemoteMessageSink remoteMessageSink, IProgressMonitor progressMonitor, string taskName,
            FileInfo file)
        {
            using (progressMonitor.BeginTask(taskName, 100))
            {
                if (progressMonitor.IsCanceled)
                    return;

                string assemblyPath = file.FullName;
                progressMonitor.SetStatus("Getting test assembly metadata.");
                AssemblyMetadata assemblyMetadata = AssemblyUtils.GetAssemblyMetadata(assemblyPath, AssemblyMetadataFields.RuntimeVersion);
                progressMonitor.Worked(2);

                if (progressMonitor.IsCanceled)
                    return;

                if (assemblyMetadata != null)
                {
                    Type driverType = GetType();
                    object[] driverArguments = GetRemoteTestDriverArguments();

                    HostSetup hostSetup = CreateHostSetup(testPackage, assemblyPath, assemblyMetadata);

                    using (var remoteProgressMonitor = new RemoteProgressMonitor(
                        progressMonitor.CreateSubProgressMonitor(97)))
                    {
                        testIsolationContext.RunIsolatedTask<ExploreOrRunTask>(hostSetup,
                            (statusMessage) => progressMonitor.SetStatus(statusMessage),
                            new object[] { driverType, driverArguments, assemblyPath, testExplorationOptions, testExecutionOptions, remoteMessageSink, remoteProgressMonitor });
                    }

                    // Record one final work unit after the isolated task has been fully cleaned up.
                    progressMonitor.SetStatus("");
                    progressMonitor.Worked(1);
                }
            }
        }
        private void ExploreOrRun(ITestIsolationContext testIsolationContext, TestPackage testPackage, TestExplorationOptions testExplorationOptions,
            TestExecutionOptions testExecutionOptions, IMessageSink messageSink, IProgressMonitor progressMonitor, string taskName)
        {
            using (progressMonitor.BeginTask(taskName, Math.Max(testPackage.Files.Count, 1)))
            {
                foreach (FileInfo file in testPackage.Files)
                {
                    if (progressMonitor.IsCanceled)
                        return;

                    RemoteMessageSink remoteMessageSink = new RemoteMessageSink(messageSink);
                    ExploreOrRunAssembly(testIsolationContext, testPackage, testExplorationOptions, testExecutionOptions,
                        remoteMessageSink, progressMonitor.CreateSubProgressMonitor(1), taskName, file);
                }
            }
        }
 /// <inheritdoc />
 protected override sealed void RunImpl(ITestIsolationContext testIsolationContext, TestPackage testPackage, TestExplorationOptions testExplorationOptions,
     TestExecutionOptions testExecutionOptions, IMessageSink messageSink, IProgressMonitor progressMonitor)
 {
     ExploreOrRun(testIsolationContext, testPackage, testExplorationOptions, testExecutionOptions, messageSink,
         progressMonitor, "Running tests.");
 }
 /// <inheritdoc />
 protected override void ExploreImpl(ITestIsolationContext testIsolationContext, TestPackage testPackage,
                                     TestExplorationOptions testExplorationOptions, IMessageSink messageSink, IProgressMonitor progressMonitor)
 {
     using (progressMonitor.BeginTask("Exploring unsupported tests.", Math.Max(testPackage.Files.Count, 1)))
     {
         PublishTestModelFromFiles(testPackage.Files, messageSink, progressMonitor);
     }
 }
            protected override void RunImpl(ITestIsolationContext testIsolationContext, TestPackage testPackage, TestExplorationOptions testExplorationOptions, TestExecutionOptions testExecutionOptions, IMessageSink messageSink, IProgressMonitor progressMonitor)
            {
                using (progressMonitor.BeginTask("Running tests.", 1))
                {
                    if (testIsolationContext.RequiresSingleThreadedExecution && !testExecutionOptions.SingleThreaded)
                    {
                        testExecutionOptions = testExecutionOptions.Copy();
                        testExecutionOptions.SingleThreaded = true;
                    }

                    ForEachDriver(testFrameworkManager.SelectTestFrameworksForFilesImpl(
                                      testFrameworkHandles, testFrameworkFallbackMode, testFrameworkOptions, testPackage.Files),
                                  (driver, items, driverCount) =>
                    {
                        TestPackage testPackageForDriver = CreateTestPackageWithFiles(testPackage, items);
                        driver.Run(testIsolationContext, testPackageForDriver, testExplorationOptions, testExecutionOptions,
                                   messageSink,
                                   progressMonitor.CreateSubProgressMonitor(1.0 / driverCount));
                        return(false);
                    });
                }
            }
        private TestPackageData MergeTestPackageData()
        {
            var merged = new TestPackage();

            foreach (Report report in reports)
                merged.MergeWith(report.TestPackage.ToTestPackage());

            return new TestPackageData(merged);
        }
        /// <inheritdoc />
        public Report Run(TestPackage testPackage, TestExplorationOptions testExplorationOptions, TestExecutionOptions testExecutionOptions, IProgressMonitor progressMonitor)
        {
            if (testPackage == null)
                throw new ArgumentNullException("testPackageConfig");
            if (testExplorationOptions == null)
                throw new ArgumentNullException("testExplorationOptions");
            if (testExecutionOptions == null)
                throw new ArgumentNullException("testExecutionOptions");
            if (progressMonitor == null)
                throw new ArgumentNullException("progressMonitor");

            ThrowIfDisposed();
            if (state != State.Initialized)
                throw new InvalidOperationException("The test runner must be initialized before this operation is performed.");

            testPackage = testPackage.Copy();
            testExplorationOptions = testExplorationOptions.Copy();
            testExecutionOptions = testExecutionOptions.Copy();
            GenericCollectionUtils.ForEach(testRunnerOptions.Properties, x => testPackage.AddProperty(x.Key, x.Value));

            using (progressMonitor.BeginTask("Running the tests.", 10))
            {
                Stopwatch stopwatch = Stopwatch.StartNew();
                Report report = new Report()
                {
                    TestPackage = new TestPackageData(testPackage),
                    TestModel = new TestModelData(),
                    TestPackageRun = new TestPackageRun()
                    {
                        StartTime = DateTime.Now
                    }
                };
                var reportLockBox = new LockBox<Report>(report);

                eventDispatcher.NotifyRunStarted(new RunStartedEventArgs(testPackage, testExplorationOptions,
                    testExecutionOptions, reportLockBox));

                bool success;
                using (Listener listener = new Listener(eventDispatcher, tappedLogger, reportLockBox))
                {
                    try
                    {
                        ITestDriver testDriver = testFrameworkManager.GetTestDriver(
                            testPackage.CreateTestFrameworkSelector(), tappedLogger);

                        using (testIsolationContext.BeginBatch(progressMonitor.SetStatus))
                        {
                            testDriver.Run(testIsolationContext, testPackage, testExplorationOptions,
                                testExecutionOptions, listener, progressMonitor.CreateSubProgressMonitor(10));
                        }

                        success = true;
                    }
                    catch (Exception ex)
                    {
                        success = false;

                        tappedLogger.Log(LogSeverity.Error,
                            "A fatal exception occurred while running tests.  Possible causes include invalid test runner parameters and stack overflows.",
                            ex);
                        report.TestModel.Annotations.Add(new AnnotationData(AnnotationType.Error,
                            CodeLocation.Unknown, CodeReference.Unknown,
                            "A fatal exception occurred while running tests.  See log for details.", null));
                    }
                    finally
                    {
                        report.TestPackageRun.EndTime = DateTime.Now;
                        report.TestPackageRun.Statistics.Duration = stopwatch.Elapsed.TotalSeconds;
                    }
                }

                eventDispatcher.NotifyRunFinished(new RunFinishedEventArgs(success, report));

                return report;
            }
        }
Exemple #24
0
 /// <inheritdoc />
 sealed protected override void RunImpl(ITestIsolationContext testIsolationContext, TestPackage testPackage, TestExplorationOptions testExplorationOptions,
                                        TestExecutionOptions testExecutionOptions, IMessageSink messageSink, IProgressMonitor progressMonitor)
 {
     ExploreOrRun(testIsolationContext, testPackage, testExplorationOptions, testExecutionOptions, messageSink,
                  progressMonitor, "Running tests.");
 }
 private static TestPackage CreateTestPackage(IEnumerable<string> sources)
 {
     var testPackage = new TestPackage();
     foreach (var source in sources)
     {
         testPackage.AddFile(new FileInfo(source));
     }
     return testPackage;
 }
Exemple #26
0
        /// <summary>
        /// Creates a copy of the test package.
        /// </summary>
        /// <returns>The new copy.</returns>
        public TestPackage Copy()
        {
            TestPackage copy = new TestPackage()
            {
                testFrameworkOptions = testFrameworkOptions != null ? testFrameworkOptions.Copy() : null,
                isTestFrameworkOptionsSpecified = isTestFrameworkOptionsSpecified,
                testFrameworkFallbackMode = testFrameworkFallbackMode,
                isTestFrameworkFallbackModeSpecified = isTestFrameworkFallbackModeSpecified,
                applicationBaseDirectory = applicationBaseDirectory,
                isApplicationBaseDirectorySpecified = isApplicationBaseDirectorySpecified,
                debuggerSetup = debuggerSetup != null ? debuggerSetup.Copy() : null,
                isDebuggerSetupSpecified = isDebuggerSetupSpecified,
                runtimeVersion = runtimeVersion,
                isRuntimeVersionSpecified = isRuntimeVersionSpecified,
                shadowCopy = shadowCopy,
                isShadowCopySpecified = isShadowCopySpecified,
                workingDirectory = workingDirectory,
                isWorkingDirectorySpecified = isWorkingDirectorySpecified
            };

            copy.excludedTestFrameworkIds.AddRange(excludedTestFrameworkIds);
            copy.files.AddRange(files);
            copy.hintDirectories.AddRange(hintDirectories);
            copy.properties.AddAll(properties);
            return copy;
        }
        private void RunAllTests(IRunContext runContext)
        {
            ITestRunnerManager runnerManager = RuntimeAccessor.ServiceLocator.Resolve<ITestRunnerManager>();
            var runner = runnerManager.CreateTestRunner(StandardTestRunnerFactoryNames.IsolatedAppDomain);
            runner.RegisterExtension(new RunContextExtension(runContext));

            ILogger logger = new RunContextLogger(runContext);
            TestRunnerOptions testRunnerOptions = new TestRunnerOptions();

            try
            {
                RunWithProgressMonitor(delegate(IProgressMonitor progressMonitor)
                {
                    runner.Initialize(testRunnerOptions, logger, progressMonitor);
                });

                if (isCanceled)
                    return;

                TestPackage testPackage = new TestPackage();
                testPackage.AddExcludedTestFrameworkId("MSTestAdapter.TestFramework");

                foreach (ITestElement testElement in runContext.RunConfig.TestElements)
                {
                    GallioTestElement gallioTestElement = testElement as GallioTestElement;
                    if (gallioTestElement != null)
                    {
                        testPackage.AddFile(new FileInfo(gallioTestElement.AssemblyPath));
                    }
                }

                TestExplorationOptions testExplorationOptions = new TestExplorationOptions();
                TestExecutionOptions testExecutionOptions = new TestExecutionOptions();

                List<Filter<string>> idFilters = new List<Filter<string>>();
                foreach (ITestElement includedTestElement in runContext.RunConfig.TestElements)
                {
                    GallioTestElement gallioTestElement = includedTestElement as GallioTestElement;
                    if (gallioTestElement != null)
                        idFilters.Add(new EqualityFilter<string>(gallioTestElement.GallioTestId));
                }

                testExecutionOptions.FilterSet = new FilterSet<ITestDescriptor>(new IdFilter<ITestDescriptor>(new OrFilter<string>(idFilters)));

                RunWithProgressMonitor(delegate(IProgressMonitor progressMonitor)
                {
                    runner.Run(testPackage, testExplorationOptions, testExecutionOptions, progressMonitor);
                });
            }
            finally
            {
                runner.Dispose(NullProgressMonitor.CreateInstance());
            }
        }
        public IEnumerable<AutoTest.TestRunners.Shared.Results.TestResult> Run(RunSettings settings)
        {
            if (!_isInitialized)
                return new AutoTest.TestRunners.Shared.Results.TestResult[] { getNotInitializedResult(settings) };
            var tests = settings.Assembly.Tests.ToList();
            var members = settings.Assembly.Members.ToList();
            var namespaces = settings.Assembly.Namespaces.ToList();

            var runAll = namespaces.Count == 0 && members.Count == 0 && tests.Count == 0;
            var steps = new List<TestStepData>();
            var testResults = new List<AutoTest.TestRunners.Shared.Results.TestResult>();

            // Get a test isolation context.  Here we want to run tests in the same AppDomain.
            var testIsolationProvider = (ITestIsolationProvider)RuntimeAccessor.ServiceLocator.ResolveByComponentId("Gallio.LocalTestIsolationProvider");
            var testIsolationOptions = new TestIsolationOptions();
            ITestIsolationContext testIsolationContext = testIsolationProvider.CreateContext(testIsolationOptions, _logger);

            var testPackage = new TestPackage();
            testPackage.AddFile(new FileInfo(settings.Assembly.Assembly));
            testPackage.TestFrameworkFallbackMode = TestFrameworkFallbackMode.Strict;

            // Create some test exploration options.  Nothing interesting for you here, probably.
            var testExplorationOptions = new TestExplorationOptions();
            var messageSink = new MessageConsumer()
                .Handle<TestStepStartedMessage>((message) =>
                {
                    steps.Add(message.Step);
                })
                .Handle<TestStepFinishedMessage>(message =>
                {
                    var test = steps.FirstOrDefault(x => x.Id.Equals(message.StepId) && x.IsTestCase);
                    if (test == null)
                        return;
                    var fixture = string.Format("{0}.{1}", test.CodeReference.NamespaceName, steps.First(x => x.Id.Equals(test.ParentId)).Name);
                    testResults.Add(new AutoTest.TestRunners.Shared.Results.TestResult(
                        "MbUnit",
                        settings.Assembly.Assembly,
                        fixture,
                        message.Result.Duration.TotalMilliseconds,
                        string.Format("{0}.{1}", fixture, test.Name),
                        convertState(message.Result.Outcome.Status),
                        message.Result.Outcome.DisplayName));
                });

            // Provide a progress monitor.
            var logProgressMonitorProvider = new LogProgressMonitorProvider(_logger);
            var options = new TestExecutionOptions();
            options.FilterSet = new Gallio.Model.Filters.FilterSet<ITestDescriptor>(new OrFilter<ITestDescriptor>(getTestFilter(namespaces, members, tests)));

            // Run the tests.
            logProgressMonitorProvider.Run((progressMonitor) =>
            {
                _testDriver.Run(testIsolationContext, testPackage, testExplorationOptions, options, messageSink, progressMonitor);
            });

            return testResults;
        }
Exemple #29
0
        /// <summary>
        /// Merges the specified package to the current one.
        /// </summary>
        /// <param name="other">The other package to be merged.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="other"/> is null.</exception>
        public void MergeWith(TestPackage other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }

            if (other.isTestFrameworkOptionsSpecified)
            {
                isTestFrameworkOptionsSpecified = true;
                testFrameworkOptions.Properties.MergeWith(other.TestFrameworkOptions.Properties);
            }

            if (other.isTestFrameworkFallbackModeSpecified && !isTestFrameworkFallbackModeSpecified)
            {
                isTestFrameworkFallbackModeSpecified = true;
                testFrameworkFallbackMode            = other.testFrameworkFallbackMode;
            }

            if (other.isShadowCopySpecified && !isShadowCopySpecified)
            {
                isShadowCopySpecified = true;
                shadowCopy           |= other.shadowCopy;
            }

            if (other.isDebuggerSetupSpecified)
            {
                isDebuggerSetupSpecified = true;

                if (other.debuggerSetup != null)
                {
                    if (debuggerSetup == null)
                    {
                        debuggerSetup = new DebuggerSetup();
                    }

                    debuggerSetup.Properties.MergeWith(other.debuggerSetup.Properties);
                }
            }

            if (other.isApplicationBaseDirectorySpecified && !isApplicationBaseDirectorySpecified)
            {
                isApplicationBaseDirectorySpecified = true;
                applicationBaseDirectory            = other.applicationBaseDirectory;
            }

            if (other.isWorkingDirectorySpecified && !isWorkingDirectorySpecified)
            {
                isWorkingDirectorySpecified = true;
                workingDirectory            = other.workingDirectory;
            }

            if (other.isRuntimeVersionSpecified && !isRuntimeVersionSpecified)
            {
                isRuntimeVersionSpecified = true;
                runtimeVersion            = other.runtimeVersion;
            }

            foreach (string item in other.excludedTestFrameworkIds)
            {
                if (!excludedTestFrameworkIds.Contains(item))
                {
                    excludedTestFrameworkIds.Add(item);
                }
            }

            foreach (FileInfo item in other.files)
            {
                if (files.FindIndex(i => i.FullName == item.FullName) < 0)
                {
                    files.Add(item);
                }
            }

            foreach (DirectoryInfo item in other.hintDirectories)
            {
                if (hintDirectories.FindIndex(i => i.FullName == item.FullName) < 0)
                {
                    hintDirectories.Add(item);
                }
            }

            properties.MergeWith(other.properties);
        }
Exemple #30
0
        private void ExploreOrRunAssembly(ITestIsolationContext testIsolationContext, TestPackage testPackage, TestExplorationOptions testExplorationOptions,
                                          TestExecutionOptions testExecutionOptions, RemoteMessageSink remoteMessageSink, IProgressMonitor progressMonitor, string taskName,
                                          FileInfo file)
        {
            using (progressMonitor.BeginTask(taskName, 100))
            {
                if (progressMonitor.IsCanceled)
                {
                    return;
                }

                string assemblyPath = file.FullName;
                progressMonitor.SetStatus("Getting test assembly metadata.");
                AssemblyMetadata assemblyMetadata = AssemblyUtils.GetAssemblyMetadata(assemblyPath, AssemblyMetadataFields.RuntimeVersion);
                progressMonitor.Worked(2);

                if (progressMonitor.IsCanceled)
                {
                    return;
                }

                if (assemblyMetadata != null)
                {
                    Type     driverType      = GetType();
                    object[] driverArguments = GetRemoteTestDriverArguments();

                    HostSetup hostSetup = CreateHostSetup(testPackage, assemblyPath, assemblyMetadata);

                    using (var remoteProgressMonitor = new RemoteProgressMonitor(
                               progressMonitor.CreateSubProgressMonitor(97)))
                    {
                        testIsolationContext.RunIsolatedTask <ExploreOrRunTask>(hostSetup,
                                                                                (statusMessage) => progressMonitor.SetStatus(statusMessage),
                                                                                new object[] { driverType, driverArguments, assemblyPath, testExplorationOptions, testExecutionOptions, remoteMessageSink, remoteProgressMonitor });
                    }

                    // Record one final work unit after the isolated task has been fully cleaned up.
                    progressMonitor.SetStatus("");
                    progressMonitor.Worked(1);
                }
            }
        }
Exemple #31
0
        /// <summary>
        /// Applies the settings of another test package as an overlay on top of this one.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Overrides scalar settings (such as <see cref="ApplicationBaseDirectory"/>) with those of
        /// the overlay when they are specified (such as when <see cref="IsApplicationBaseDirectorySpecified" /> is true).
        /// Merges aggregate settings (such as lists of files).
        /// </para>
        /// </remarks>
        /// <param name="overlay">The test package to overlay on top of this one.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="overlay"/> is null.</exception>
        public void ApplyOverlay(TestPackage overlay)
        {
            if (overlay == null)
                throw new ArgumentNullException("overlay");

            if (overlay.IsApplicationBaseDirectorySpecified)
                ApplicationBaseDirectory = overlay.ApplicationBaseDirectory;
            if (overlay.IsDebuggerSetupSpecified)
                DebuggerSetup = overlay.DebuggerSetup;
            if (overlay.IsRuntimeVersionSpecified)
                RuntimeVersion = overlay.RuntimeVersion;
            if (overlay.IsTestFrameworkOptionsSpecified)
                TestFrameworkOptions = overlay.TestFrameworkOptions;
            if (overlay.IsTestFrameworkFallbackModeSpecified)
                TestFrameworkFallbackMode = overlay.TestFrameworkFallbackMode;
            if (overlay.IsShadowCopySpecified)
                ShadowCopy = overlay.ShadowCopy;
            if (overlay.IsWorkingDirectorySpecified)
                WorkingDirectory = overlay.WorkingDirectory;

            GenericCollectionUtils.ForEach(overlay.Files, x => AddFile(x));
            GenericCollectionUtils.ForEach(overlay.HintDirectories, x => AddHintDirectory(x));
            GenericCollectionUtils.ForEach(overlay.ExcludedTestFrameworkIds, x => AddExcludedTestFrameworkId(x));
            GenericCollectionUtils.ForEach(overlay.Properties, x => properties[x.Key] = x.Value);
        }
        /// <inheritdoc />
        protected override void RunImpl(ITestIsolationContext testIsolationContext, TestPackage testPackage,
            TestExplorationOptions testExplorationOptions, TestExecutionOptions testExecutionOptions,
            IMessageSink messageSink, IProgressMonitor progressMonitor)
        {
            double workItems = Math.Max(testPackage.Files.Count, 1);
            using (progressMonitor.BeginTask("Running unsupported tests.", workItems * 2))
            {
                TestModel testModel = PublishTestModelFromFiles(testPackage.Files, messageSink, progressMonitor);

                if (testModel != null)
                    RunTestModel(testModel, messageSink, progressMonitor, workItems);
            }
        }
Exemple #33
0
        /// <summary>
        /// Merges the specified package to the current one.
        /// </summary>
        /// <param name="other">The other package to be merged.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="other"/> is null.</exception>
        public void MergeWith(TestPackage other)
        {
            if (other == null)
                throw new ArgumentNullException("other");

            if (other.isTestFrameworkOptionsSpecified)
            {
                isTestFrameworkOptionsSpecified = true;
                testFrameworkOptions.Properties.MergeWith(other.TestFrameworkOptions.Properties);
            }

            if (other.isTestFrameworkFallbackModeSpecified && !isTestFrameworkFallbackModeSpecified)
            {
                isTestFrameworkFallbackModeSpecified = true;
                testFrameworkFallbackMode = other.testFrameworkFallbackMode;
            }

            if (other.isShadowCopySpecified && !isShadowCopySpecified)
            {
                isShadowCopySpecified = true;
                shadowCopy |= other.shadowCopy;
            }

            if (other.isDebuggerSetupSpecified)
            {
                isDebuggerSetupSpecified = true;

                if (other.debuggerSetup != null)
                {
                    if (debuggerSetup == null)
                        debuggerSetup = new DebuggerSetup();

                    debuggerSetup.Properties.MergeWith(other.debuggerSetup.Properties);
                }
            }

            if (other.isApplicationBaseDirectorySpecified && !isApplicationBaseDirectorySpecified)
            {
                isApplicationBaseDirectorySpecified = true;
                applicationBaseDirectory = other.applicationBaseDirectory;
            }

            if (other.isWorkingDirectorySpecified && !isWorkingDirectorySpecified)
            {
                isWorkingDirectorySpecified = true;
                workingDirectory = other.workingDirectory;
            }

            if (other.isRuntimeVersionSpecified && !isRuntimeVersionSpecified)
            {
                isRuntimeVersionSpecified = true;
                runtimeVersion = other.runtimeVersion;
            }

            foreach (string item in other.excludedTestFrameworkIds)
            {
                if (!excludedTestFrameworkIds.Contains(item))
                    excludedTestFrameworkIds.Add(item);
            }

            foreach (FileInfo item in other.files)
            {
                if (files.FindIndex(i => i.FullName == item.FullName) < 0)
                    files.Add(item);
            }

            foreach (DirectoryInfo item in other.hintDirectories)
            {
                if (hintDirectories.FindIndex(i => i.FullName == item.FullName) < 0)
                    hintDirectories.Add(item);
            }

            properties.MergeWith(other.properties);
        }
 /// <inheritdoc />
 protected override void ExploreImpl(ITestIsolationContext testIsolationContext, TestPackage testPackage,
     TestExplorationOptions testExplorationOptions, IMessageSink messageSink, IProgressMonitor progressMonitor)
 {
     using (progressMonitor.BeginTask("Exploring unsupported tests.", Math.Max(testPackage.Files.Count, 1)))
     {
         PublishTestModelFromFiles(testPackage.Files, messageSink, progressMonitor);
     }
 }
        private List<Test> getTests(string assembly)
        {
            var testIsolationProvider = (ITestIsolationProvider)RuntimeAccessor.ServiceLocator.ResolveByComponentId("Gallio.LocalTestIsolationProvider");
            var testIsolationOptions = new TestIsolationOptions();
            ITestIsolationContext testIsolationContext = testIsolationProvider.CreateContext(testIsolationOptions, _logger);

            // Create a test package.
            // You can set a whole bunch of options here.
            var testPackage = new TestPackage();
            testPackage.AddFile(new FileInfo(assembly));
            testPackage.TestFrameworkFallbackMode = TestFrameworkFallbackMode.Strict;

            var testExplorationOptions = new TestExplorationOptions();

            // This query you can answer by exploring tests and looking at their metadata for "TestsOn".
            // You can explore tests using the Explore method of TestDriver. It sends a bunch of
            // messages to an IMessageSink just like Run.  Just scan these messages for tests that
            // match the pattern you like.

            // Alternately, you can build a TestModel once up front and traverse the resulting test tree
            // to find what you need.  The Explore method of testDriver is just like Run, except that
            // it does not run the tests.
            // TestModelSerializer is a little helper we can use to build up a TestModel from test messages on the fly.
            // The TestModel is just a tree of test metadata.  Pretty straightforward.
            TestModel testModel = new TestModel();
            IMessageSink messageSink = TestModelSerializer.CreateMessageSinkToPopulateTestModel(testModel);

            var logProgressMonitorProvider = new LogProgressMonitorProvider(_logger);

            logProgressMonitorProvider.Run((progressMonitor) =>
            {
                _testDriver.Explore(testIsolationContext, testPackage, testExplorationOptions, messageSink, progressMonitor);
            });

            return testModel.AllTests.Where(x => x.IsTestCase).ToList();
        }
Exemple #36
0
 /// <summary>
 /// Runs tests from a test package.
 /// </summary>
 /// <remarks>
 /// <para>
 /// The default implementation does nothing.  Subclasses may override to enable tests
 /// to be run.  This is required for actually running tests.
 /// </para>
 /// </remarks>
 /// <param name="testIsolationContext">The test isolation context, not null.</param>
 /// <param name="testPackage">The test package, not null.</param>
 /// <param name="testExplorationOptions">The test exploration options, not null.</param>
 /// <param name="testExecutionOptions">The test execution options, not null.</param>
 /// <param name="messageSink">The message sink to receive test exploration and execution messages, not null.</param>
 /// <param name="progressMonitor">The progress monitor, not null.</param>
 /// <returns>The test report.</returns>
 protected virtual void RunImpl(ITestIsolationContext testIsolationContext, TestPackage testPackage,
                                TestExplorationOptions testExplorationOptions, TestExecutionOptions testExecutionOptions,
                                IMessageSink messageSink, IProgressMonitor progressMonitor)
 {
 }
    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;
    }
 protected override FileInfo GetTestDriverScriptFile(TestPackage testPackage)
 {
     return new FileInfo(Path.Combine(pluginBaseDirectory.FullName, @"Scripts\driver.rb"));
 }