Пример #1
0
        /// <inheritdoc />
        sealed protected override void ExploreAssembly(Assembly assembly, TestExplorationOptions testExplorationOptions, IMessageSink messageSink, IProgressMonitor progressMonitor)
        {
            using (progressMonitor.BeginTask(string.Format("Exploring {0} tests.", FrameworkName), 5))
            {
                using (TestHarness testHarness = CreateTestHarness())
                {
                    IDisposable appDomainState = null;
                    try
                    {
                        progressMonitor.SetStatus("Setting up the test harness.");
                        appDomainState = testHarness.SetUpAppDomain();
                        progressMonitor.Worked(1);

                        progressMonitor.SetStatus("Building the test model.");
                        GenerateTestModel(assembly, messageSink);
                        progressMonitor.Worked(3);
                    }
                    finally
                    {
                        progressMonitor.SetStatus("Tearing down the test harness.");
                        if (appDomainState != null)
                        {
                            appDomainState.Dispose();
                        }
                        progressMonitor.Worked(1);
                    }
                }
            }
        }
Пример #2
0
        /// <inheritdoc />
        protected override void Execute(UnmanagedTestRepository repository, IProgressMonitor progressMonitor)
        {
            using (progressMonitor.BeginTask("Running " + repository.FileName, 4))
            {
                progressMonitor.SetStatus("Building the test model.");
                BuildTestModel(repository, progressMonitor);
                progressMonitor.Worked(1);

                progressMonitor.SetStatus("Running the tests.");
                RunTests(repository, progressMonitor);
                progressMonitor.Worked(3);
            }
        }
Пример #3
0
        /// <inheritdoc />
        protected override void Execute(UnmanagedTestRepository repository, IProgressMonitor progressMonitor)
        {
            using (progressMonitor.BeginTask("Running " + repository.FileName, 4))
            {
                progressMonitor.SetStatus("Building the test model.");
                BuildTestModel(repository, progressMonitor);
                progressMonitor.Worked(1);

                progressMonitor.SetStatus("Running the tests.");
                RunTests(repository, progressMonitor);
                progressMonitor.Worked(3);
            }
        }
Пример #4
0
        /// <inheritdoc />
        public void SaveReport(AttachmentContentDisposition attachmentContentDisposition,
                               IProgressMonitor progressMonitor)
        {
            if (progressMonitor == null)
            {
                throw new ArgumentNullException(@"progressMonitor");
            }

            if (reportSaved)
            {
                return;
            }

            int attachmentCount = CountAttachments(report);

            using (progressMonitor.BeginTask("Saving report.", attachmentCount + 1))
            {
                var encoding = new UTF8Encoding(false);
                var settings = new XmlWriterSettings();
                settings.CheckCharacters = false;
                settings.Indent          = true;
                settings.Encoding        = encoding;
                settings.CloseOutput     = true;

                string reportPath = reportContainer.ReportName + @".xml";

                progressMonitor.ThrowIfCanceled();
                progressMonitor.SetStatus(reportPath);

                using (XmlWriter writer = XmlWriter.Create(reportContainer.OpenWrite(reportPath, MimeTypes.Xml, settings.Encoding), settings))
                {
                    progressMonitor.ThrowIfCanceled();
                    SerializeReport(writer, attachmentContentDisposition);
                }

                progressMonitor.Worked(1);
                progressMonitor.SetStatus(@"");

                if (attachmentContentDisposition == AttachmentContentDisposition.Link && attachmentCount != 0)
                {
                    progressMonitor.ThrowIfCanceled();
                    using (IProgressMonitor subProgressMonitor = progressMonitor.CreateSubProgressMonitor(attachmentCount))
                        SaveReportAttachments(subProgressMonitor);
                }

                AddReportDocumentPath(reportPath);
                reportSaved = true;
            }
        }
Пример #5
0
        public TestOutcome RunSession(ITestContext assemblyTestContext, MSTestAssembly assemblyTest,
                                      ITestCommand assemblyTestCommand, TestStep parentTestStep, IProgressMonitor progressMonitor)
        {
            DirectoryInfo tempDir = SpecialPathPolicy.For("MSTestAdapter").CreateTempDirectoryWithUniqueName();

            try
            {
                // Set the test results path.  Among other things, the test results path
                // will determine where the deployed test files go.
                string testResultsPath = Path.Combine(tempDir.FullName, "tests.trx");

                // Set the test results root directory.
                // This path determines both where MSTest searches for test files which
                // is used to resolve relative paths to test files in the "*.vsmdi" file.
                string searchPathRoot = Path.GetDirectoryName(assemblyTest.AssemblyFilePath);

                // Set the test metadata and run config paths.  These are just temporary
                // files that can go anywhere on the filesystem.  It happens to be convenient
                // to store them in the same temporary directory as the test results.
                string testMetadataPath = Path.Combine(tempDir.FullName, "tests.vsmdi");
                string runConfigPath    = Path.Combine(tempDir.FullName, "tests.runconfig");

                progressMonitor.SetStatus("Generating test metadata file.");
                CreateTestMetadataFile(testMetadataPath,
                                       GetTestsFromCommands(assemblyTestCommand.PreOrderTraversal), assemblyTest.AssemblyFilePath);

                progressMonitor.SetStatus("Generating run config file.");
                CreateRunConfigFile(runConfigPath);

                progressMonitor.SetStatus("Executing tests.");
                Executor    executor = new Executor(this, assemblyTestContext, assemblyTestCommand);
                TestOutcome outcome  = executor.Execute(testMetadataPath, testResultsPath,
                                                        runConfigPath, searchPathRoot);
                return(outcome);
            }
            finally
            {
                try
                {
                    tempDir.Delete(true);
                }
                catch
                {
                    // Ignore I/O exceptions deleting temporary files.
                    // They will probably be deleted by the OS later on during a file cleanup.
                }
            }
        }
Пример #6
0
        private TestResult RunTest(ITestCommand testCommand, TestStep parentTestStep, IProgressMonitor progressMonitor)
        {
            Test test = testCommand.Test;
            progressMonitor.SetStatus(test.Name);

            // The first test should be an assembly test
            MSTestAssembly assemblyTest = testCommand.Test as MSTestAssembly;
            TestOutcome outcome;
            TestResult result;
            if (assemblyTest != null)
            {
                ITestContext assemblyContext = testCommand.StartPrimaryChildStep(parentTestStep);
                try
                {
                    MSTestRunner runner = MSTestRunner.GetRunnerForFrameworkVersion(frameworkVersion);

                    outcome = runner.RunSession(assemblyContext, assemblyTest,
                        testCommand, parentTestStep, progressMonitor);
                }
                catch (Exception ex)
                {
                    assemblyContext.LogWriter.Failures.WriteException(ex, "Internal Error");
                    outcome = TestOutcome.Error;
                }

                result = assemblyContext.FinishStep(outcome, null);
            }
            else
            {
                result = new TestResult(TestOutcome.Skipped);
            }

            progressMonitor.Worked(1);
            return result;
        }
Пример #7
0
        public TestOutcome RunSession(ITestContext assemblyTestContext, MSTestAssembly assemblyTest,
            ITestCommand assemblyTestCommand, TestStep parentTestStep, IProgressMonitor progressMonitor)
        {
            DirectoryInfo tempDir = SpecialPathPolicy.For("MSTestAdapter").CreateTempDirectoryWithUniqueName();
            try
            {
                // Set the test results path.  Among other things, the test results path
                // will determine where the deployed test files go.
                string testResultsPath = Path.Combine(tempDir.FullName, "tests.trx");

                // Set the test results root directory.
                // This path determines both where MSTest searches for test files which
                // is used to resolve relative paths to test files in the "*.vsmdi" file.
                string searchPathRoot = Path.GetDirectoryName(assemblyTest.AssemblyFilePath);

                // Set the test metadata and run config paths.  These are just temporary
                // files that can go anywhere on the filesystem.  It happens to be convenient
                // to store them in the same temporary directory as the test results.
                string testMetadataPath = Path.Combine(tempDir.FullName, "tests.vsmdi");
                string runConfigPath = Path.Combine(tempDir.FullName, "tests.runconfig");

                progressMonitor.SetStatus("Generating test metadata file.");
                CreateTestMetadataFile(testMetadataPath,
                    GetTestsFromCommands(assemblyTestCommand.PreOrderTraversal), assemblyTest.AssemblyFilePath);

                progressMonitor.SetStatus("Generating run config file.");
                CreateRunConfigFile(runConfigPath);

                progressMonitor.SetStatus("Executing tests.");
                Executor executor = new Executor(this, assemblyTestContext, assemblyTestCommand);
                TestOutcome outcome = executor.Execute(testMetadataPath, testResultsPath,
                    runConfigPath, searchPathRoot);
                return outcome;
            }
            finally
            {
                try
                {
                    tempDir.Delete(true);
                }
                catch
                {
                    // Ignore I/O exceptions deleting temporary files.
                    // They will probably be deleted by the OS later on during a file cleanup.
                }
            }
        }
Пример #8
0
 /// <inheritdoc />
 sealed protected override void DescribeImpl(IReflectionPolicy reflectionPolicy, IList <ICodeElementInfo> codeElements, TestExplorationOptions testExplorationOptions, IMessageSink messageSink, IProgressMonitor progressMonitor)
 {
     using (progressMonitor.BeginTask(string.Format("Describing {0} tests.", FrameworkName), 100))
     {
         progressMonitor.SetStatus("Building the test model.");
         GenerateTestModel(reflectionPolicy, codeElements, messageSink);
     }
 }
            void ITestListener.OnAssemblyStarted(object sender, AssemblyEventArgs args)
            {
                ITestCommand testCommand;
                string       testName = args.AssemblyFullName.Split(',')[0];

                if (!testCommandsByName.TryGetValue(testName, out testCommand))
                {
                    return;
                }

                progressMonitor.SetStatus(testCommand.Test.Name);

                ITestContext testContext = testCommand.StartPrimaryChildStep(topTestStep);

                testContext.LifecyclePhase = LifecyclePhases.Execute;
                testContextStack.Push(testContext);
                assemblyFailureCount = 0;
                assemblyErrorCount   = 0;
            }
Пример #10
0
        private TestResult RunTest(ITestCommand testCommand, TestStep parentTestStep,
                                   TestExecutionOptions options, IProgressMonitor progressMonitor)
        {
            // NOTE: This method has been optimized to minimize the total stack depth of the action
            //       by inlining blocks on the critical path that had previously been factored out.

            using (TestController testController = testControllerProvider(testCommand.Test))
            {
                if (testController != null)
                {
                    try
                    {
                        using (IProgressMonitor subProgressMonitor = progressMonitor.CreateSubProgressMonitor(testCommand.TestCount))
                        {
                            // Calling RunImpl directly instead of Run to minimize stack depth
                            // because we already know the arguments are valid.
                            return(testController.RunImpl(testCommand, parentTestStep, options, subProgressMonitor));
                        }
                    }
                    catch (Exception ex)
                    {
                        ITestContext context = testCommand.StartPrimaryChildStep(parentTestStep);
                        context.LogWriter.Failures.WriteException(ex, "Fatal Exception in test controller");
                        return(context.FinishStep(TestOutcome.Error, null));
                    }
                }
            }

            // Enter the scope of the test and recurse until we find a controller.
            progressMonitor.SetStatus(testCommand.Test.FullName);

            ITestContext testContext = testCommand.StartPrimaryChildStep(parentTestStep);
            TestOutcome  outcome     = TestOutcome.Passed;

            foreach (ITestCommand monitor in testCommand.Children)
            {
                if (progressMonitor.IsCanceled)
                {
                    break;
                }

                TestResult childResult = RunTest(monitor, testContext.TestStep, options, progressMonitor);
                outcome = outcome.CombineWith(childResult.Outcome).Generalize();
            }

            if (progressMonitor.IsCanceled)
            {
                outcome = TestOutcome.Canceled;
            }

            TestResult result = testContext.FinishStep(outcome, null);

            progressMonitor.Worked(1);
            return(result);
        }
Пример #11
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);
                }
            }
        }
Пример #12
0
        private TestResult RunTest(ITestCommand testCommand, TestStep parentTestStep, IProgressMonitor progressMonitor)
        {
            Test test = testCommand.Test;

            progressMonitor.SetStatus(test.Name);
            var mbUnitCppTest = test as MbUnitCppTest;

            return(((mbUnitCppTest == null) || mbUnitCppTest.TestInfoData.HasChildren)
                ? RunChildTests(testCommand, parentTestStep, progressMonitor)
                : RunTestStep(testCommand, mbUnitCppTest.TestInfoData, parentTestStep, progressMonitor));
        }
Пример #13
0
        /// <inheritdoc />
        public Report LoadReport(bool loadAttachmentContents, IProgressMonitor progressMonitor)
        {
            if (progressMonitor == null)
            {
                throw new ArgumentNullException(@"progressMonitor");
            }

            using (progressMonitor.BeginTask(String.Format("Loading report '{0}'.", reportContainer.ReportName), 10))
            {
                string reportPath = reportContainer.ReportName + @".xml";

                progressMonitor.ThrowIfCanceled();
                progressMonitor.SetStatus(reportPath);

                var serializer = new XmlSerializer(typeof(Report));

                Report report;
                using (Stream stream = reportContainer.OpenRead(reportPath))
                {
                    progressMonitor.ThrowIfCanceled();
                    report = (Report)serializer.Deserialize(stream);
                }

                FixImplicitIds(report);

                progressMonitor.Worked(1);
                progressMonitor.SetStatus(@"");

                if (loadAttachmentContents)
                {
                    progressMonitor.ThrowIfCanceled();
                    using (IProgressMonitor subProgressMonitor = progressMonitor.CreateSubProgressMonitor(9))
                        LoadReportAttachments(report, subProgressMonitor);
                }

                return(report);
            }
        }
Пример #14
0
        /// <inheritdoc />
        public override void Format(IReportWriter reportWriter, ReportFormatterOptions options, IProgressMonitor progressMonitor)
        {
            AttachmentContentDisposition attachmentContentDisposition = GetAttachmentContentDisposition(options);

            using (progressMonitor.BeginTask("Formatting report.", 10))
            {
                progressMonitor.SetStatus("Applying template.");
                ApplyTemplate(reportWriter, attachmentContentDisposition, options);
                progressMonitor.Worked(3);

                progressMonitor.SetStatus("Copying resources.");
                CopyResources(reportWriter);
                progressMonitor.Worked(2);

                progressMonitor.SetStatus(@"");

                if (attachmentContentDisposition == AttachmentContentDisposition.Link)
                {
                    using (IProgressMonitor subProgressMonitor = progressMonitor.CreateSubProgressMonitor(5))
                        reportWriter.SaveReportAttachments(subProgressMonitor);
                }
            }
        }
Пример #15
0
        private void InstallRegistryKeysForIcarus(string icarusPath, IProgressMonitor progressMonitor, RegistryKey hiveKey, string rootKeyPath)
        {
            string subKeyName = string.Concat(rootKeyPath, @"\", RunnerRegKeyPrefix + "_Icarus"); // Note: 'Gallio_Icarus' is hardcoded in TDNet's config file.
            string message    = "Adding TestDriven.Net runner registry key for Icarus.";

            logger.Log(LogSeverity.Info, message);
            progressMonitor.SetStatus(message);

            using (RegistryKey subKey = hiveKey.CreateSubKey(subKeyName, RegistryKeyPermissionCheck.ReadWriteSubTree))
            {
                subKey.SetValue(null, "1");
                subKey.SetValue("Application", icarusPath);
            }
        }
Пример #16
0
        /// <inheritdoc />
        public void LoadReportAttachments(Report report, IProgressMonitor progressMonitor)
        {
            if (progressMonitor == null)
            {
                throw new ArgumentNullException(@"progressMonitor");
            }

            if (report.TestPackageRun == null)
            {
                return;
            }

            var attachmentsToLoad = new List <AttachmentData>();

            foreach (TestStepRun testStepRun in report.TestPackageRun.AllTestStepRuns)
            {
                foreach (AttachmentData attachment in testStepRun.TestLog.Attachments)
                {
                    if (attachment.ContentPath != null)
                    {
                        attachmentsToLoad.Add(attachment);
                    }
                }
            }

            if (attachmentsToLoad.Count == 0)
            {
                return;
            }

            using (progressMonitor.BeginTask("Loading report attachments.", attachmentsToLoad.Count))
            {
                foreach (AttachmentData attachment in attachmentsToLoad)
                {
                    progressMonitor.ThrowIfCanceled();

                    if (attachment.ContentDisposition != AttachmentContentDisposition.Link ||
                        attachment.ContentPath == null)
                    {
                        continue;
                    }

                    string attachmentPath = attachment.ContentPath;

                    progressMonitor.SetStatus(attachmentPath);
                    LoadAttachmentContents(attachment, attachmentPath);
                }
            }
        }
Пример #17
0
        private void InstallRegistryKeysForFramework(string frameworkName, AssemblySignature frameworkAssembly, int priority, IProgressMonitor progressMonitor, RegistryKey hiveKey, string rootKeyPath)
        {
            string subKeyName = string.Concat(rootKeyPath, @"\", RunnerRegKeyPrefix, " - ", frameworkName, " (", frameworkAssembly, ")");
            string message    = string.Format("Adding TestDriven.Net runner registry key for framework '{0}'.", frameworkName);

            logger.Log(LogSeverity.Info, message);
            progressMonitor.SetStatus(message);

            using (RegistryKey subKey = hiveKey.CreateSubKey(subKeyName, RegistryKeyPermissionCheck.ReadWriteSubTree))
            {
                subKey.SetValue(null, priority.ToString());
                subKey.SetValue("AssemblyPath", AssemblyUtils.GetAssemblyLocalPath(GetType().Assembly));
                subKey.SetValue("TargetFrameworkAssemblyName", frameworkAssembly.ToString()); // n.b. TDNet supports version ranges in the same format we use
                subKey.SetValue("TypeName", "Gallio.TDNetRunner.GallioTestRunner");
                subKey.SetValue("TypeName_Resident", "Gallio.TDNetRunner.GallioResidentTestRunner");
            }
        }
Пример #18
0
            private void HandleTestOrSuiteStarted(TestName testName)
            {
                ITestCommand testCommand;

                if (!testCommandsByTestName.TryGetValue(testName, out testCommand))
                {
                    return;
                }

                progressMonitor.SetStatus(testCommand.Test.Name);

                TestStep     parentTestStep = testContextStack.Count != 0 ? testContextStack.Peek().TestStep : topTestStep;
                ITestContext testContext    = testCommand.StartPrimaryChildStep(parentTestStep);

                testContextStack.Push(testContext);

                testContext.LifecyclePhase = LifecyclePhases.Execute;
            }
Пример #19
0
        /// <inheritdoc />
        public void Dispose(IProgressMonitor progressMonitor)
        {
            if (progressMonitor == null)
            {
                throw new ArgumentNullException("progressMonitor");
            }
            if (state == State.Disposed)
            {
                return;
            }

            using (progressMonitor.BeginTask("Disposing the test runner.", 10))
            {
                bool success;
                try
                {
                    eventDispatcher.NotifyDisposeStarted(new DisposeStartedEventArgs());

                    if (testIsolationContext != null)
                    {
                        progressMonitor.SetStatus("Disposing the test isolation context.");

                        testIsolationContext.Dispose();
                        testIsolationContext = null;
                    }

                    progressMonitor.Worked(10);
                    success = true;
                }
                catch (Exception ex)
                {
                    if (tappedLogger != null)
                    {
                        tappedLogger.Log(LogSeverity.Warning, "An exception occurred while disposing the test isolation context.  This may indicate that the test isolation context previously encountered another fault from which it could not recover.", ex);
                    }
                    success = false;
                }

                state = State.Disposed;
                eventDispatcher.NotifyDisposeFinished(new DisposeFinishedEventArgs(success));

                UnhandledExceptionPolicy.ReportUnhandledException -= OnUnhandledException;
            }
        }
Пример #20
0
        private static TestResult RunTest(ITestCommand testCommand, TestStep parentTestStep, IProgressMonitor progressMonitor)
        {
            Test test = testCommand.Test;
            progressMonitor.SetStatus(test.Name);

            TestResult result;
            XunitTest xunitTest = test as XunitTest;
            if (xunitTest == null)
            {
                result = RunChildTests(testCommand, parentTestStep, progressMonitor);
            }
            else
            {
                result = RunTestFixture(testCommand, xunitTest.TypeInfo, parentTestStep);
            }

            progressMonitor.Worked(1);
            return result;
        }
        private static TestResult RunTest(ITestCommand testCommand, TestStep parentTestStep, IProgressMonitor progressMonitor)
        {
            Test test = testCommand.Test;
            progressMonitor.SetStatus(test.Name);

            TestResult result;
            ConcordionTest concordionTest = test as ConcordionTest;
            if (concordionTest == null)
            {
                result = RunChildTests(testCommand, parentTestStep, progressMonitor);
            }
            else
            {
                result = RunTestFixture(testCommand, concordionTest, parentTestStep);
            }

            progressMonitor.Worked(1);
            return result;
        }
    private void RunTest(ITestCommand testCommand, ITestStep parentTestStep, IProgressMonitor progressMonitor)
    {
      ITest test = testCommand.Test;
      progressMonitor.SetStatus(test.Name);

      MachineSpecificationTest specification = test as MachineSpecificationTest;
      MachineContextTest description = test as MachineContextTest;
      if (specification != null)
      {
        //RunContextTest(specification, testComman);
      }
      else if (description != null)
      {
        RunContextTest(description, testCommand, parentTestStep);
      }
      else
      {
        Debug.WriteLine("Got something weird " + test.GetType().ToString());
      }
    }
        private static bool RunTest(ITestCommand testCommand, ITestStep parentTestStep, IProgressMonitor progressMonitor)
        {
            ITest test = testCommand.Test;

            progressMonitor.SetStatus(test.Name);

            bool           passed;
            ConcordionTest concordionTest = test as ConcordionTest;

            if (concordionTest == null)
            {
                passed = RunChildTests(testCommand, parentTestStep, progressMonitor);
            }
            else
            {
                passed = RunTestFixture(testCommand, concordionTest, parentTestStep);
            }

            progressMonitor.Worked(1);
            return(passed);
        }
Пример #24
0
        private void CopyFile(IProgressMonitor progressMonitor, string filePath)
        {
            try
            {
                var destinationFilePath = Path.Combine(destinationFolder, filePath);
                
                progressMonitor.SetStatus(destinationFilePath);

                var sourceFilePath = Path.Combine(sourceFolder, filePath);

                var destinationDirectory = Path.GetDirectoryName(destinationFilePath);
                if (!fileSystem.DirectoryExists(destinationDirectory))
                    fileSystem.CreateDirectory(destinationDirectory);

                fileSystem.CopyFile(sourceFilePath, destinationFilePath, true);
            }
            catch (Exception ex)
            {
                unhandledExceptionPolicy.Report(string.Format("Error copying file '{0}'.", filePath), ex);
            }
        }
Пример #25
0
        private static TestResult RunTest(ITestCommand testCommand, TestStep parentTestStep, IProgressMonitor progressMonitor)
        {
            Test test = testCommand.Test;

            progressMonitor.SetStatus(test.Name);

            TestResult     result;
            ConcordionTest concordionTest = test as ConcordionTest;

            if (concordionTest == null)
            {
                result = RunChildTests(testCommand, parentTestStep, progressMonitor);
            }
            else
            {
                result = RunTestFixture(testCommand, concordionTest, parentTestStep);
            }

            progressMonitor.Worked(1);
            return(result);
        }
Пример #26
0
        private static TestResult RunTest(ITestCommand testCommand, TestStep parentTestStep, IProgressMonitor progressMonitor)
        {
            Test test = testCommand.Test;

            progressMonitor.SetStatus(test.Name);

            TestResult result;
            XunitTest  xunitTest = test as XunitTest;

            if (xunitTest == null)
            {
                result = RunChildTests(testCommand, parentTestStep, progressMonitor);
            }
            else
            {
                result = RunTestFixture(testCommand, xunitTest.TypeInfo, parentTestStep);
            }

            progressMonitor.Worked(1);
            return(result);
        }
Пример #27
0
        /// <inheritdoc />
        public void SaveReportAttachments(IProgressMonitor progressMonitor)
        {
            if (progressMonitor == null)
            {
                throw new ArgumentNullException(@"progressMonitor");
            }

            if (reportAttachmentsSaved)
            {
                return;
            }

            int attachmentCount = CountAttachments(report);

            if (attachmentCount == 0)
            {
                return;
            }

            using (progressMonitor.BeginTask("Saving report attachments.", attachmentCount))
            {
                foreach (TestStepRun testStepRun in report.TestPackageRun.AllTestStepRuns)
                {
                    foreach (AttachmentData attachment in testStepRun.TestLog.Attachments)
                    {
                        string attachmentPath = attachmentPathResolver.GetAttachmentPath(testStepRun.Step.Id, attachment.Name, attachment.ContentType);

                        progressMonitor.ThrowIfCanceled();
                        progressMonitor.SetStatus(attachmentPath);

                        SaveAttachmentContents(attachment, attachmentPath);

                        progressMonitor.Worked(1);
                    }
                }

                reportAttachmentsSaved = true;
            }
        }
Пример #28
0
        private void CopyFile(IProgressMonitor progressMonitor, string filePath)
        {
            try
            {
                var destinationFilePath = Path.Combine(destinationFolder, filePath);

                progressMonitor.SetStatus(destinationFilePath);

                var sourceFilePath = Path.Combine(sourceFolder, filePath);

                var destinationDirectory = Path.GetDirectoryName(destinationFilePath);
                if (!fileSystem.DirectoryExists(destinationDirectory))
                {
                    fileSystem.CreateDirectory(destinationDirectory);
                }

                fileSystem.CopyFile(sourceFilePath, destinationFilePath, true);
            }
            catch (Exception ex)
            {
                unhandledExceptionPolicy.Report(string.Format("Error copying file '{0}'.", filePath), ex);
            }
        }
Пример #29
0
        private void RemoveExistingRegistryKeys(IProgressMonitor progressMonitor, RegistryKey hiveKey, string rootKeyPath)
        {
            using (RegistryKey rootKey = hiveKey.OpenSubKey(rootKeyPath, true))
            {
                if (rootKey == null)
                {
                    return;
                }

                foreach (string subKeyName in rootKey.GetSubKeyNames())
                {
                    if (subKeyName.StartsWith(RunnerRegKeyPrefix))
                    {
                        string message = string.Format("Deleting TestDriven.Net runner registry key '{0}'.", subKeyName);

                        logger.Log(LogSeverity.Info, message);
                        progressMonitor.SetStatus(message);

                        rootKey.DeleteSubKeyTree(subKeyName);
                    }
                }
            }
        }
Пример #30
0
        private TestResult RunTest(ITestCommand testCommand, TestStep parentTestStep, IProgressMonitor progressMonitor)
        {
            Test test = testCommand.Test;

            progressMonitor.SetStatus(test.Name);

            // The first test should be an assembly test
            MSTestAssembly assemblyTest = testCommand.Test as MSTestAssembly;
            TestOutcome    outcome;
            TestResult     result;

            if (assemblyTest != null)
            {
                ITestContext assemblyContext = testCommand.StartPrimaryChildStep(parentTestStep);
                try
                {
                    MSTestRunner runner = MSTestRunner.GetRunnerForFrameworkVersion(frameworkVersion);

                    outcome = runner.RunSession(assemblyContext, assemblyTest,
                                                testCommand, parentTestStep, progressMonitor);
                }
                catch (Exception ex)
                {
                    assemblyContext.LogWriter.Failures.WriteException(ex, "Internal Error");
                    outcome = TestOutcome.Error;
                }

                result = assemblyContext.FinishStep(outcome, null);
            }
            else
            {
                result = new TestResult(TestOutcome.Skipped);
            }

            progressMonitor.Worked(1);
            return(result);
        }
Пример #31
0
        /// <inheritdoc />
        public Report LoadReport(bool loadAttachmentContents, IProgressMonitor progressMonitor)
        {
            if (progressMonitor == null)
                throw new ArgumentNullException(@"progressMonitor");

            using (progressMonitor.BeginTask(String.Format("Loading report '{0}'.", reportContainer.ReportName), 10))
            {
                string reportPath = reportContainer.ReportName + @".xml";

                progressMonitor.ThrowIfCanceled();
                progressMonitor.SetStatus(reportPath);

                var serializer = new XmlSerializer(typeof(Report));

                Report report;
                using (Stream stream = reportContainer.OpenRead(reportPath))
                {
                    progressMonitor.ThrowIfCanceled();
                    report = (Report)serializer.Deserialize(stream);
                }

                FixImplicitIds(report);

                progressMonitor.Worked(1);
                progressMonitor.SetStatus(@"");

                if (loadAttachmentContents)
                {
                    progressMonitor.ThrowIfCanceled();
                    using (IProgressMonitor subProgressMonitor = progressMonitor.CreateSubProgressMonitor(9))
                        LoadReportAttachments(report, subProgressMonitor);
                }

                return report;
            }
        }
Пример #32
0
        private void InstallRegistryKeysForIcarus(string icarusPath, IProgressMonitor progressMonitor, RegistryKey hiveKey, string rootKeyPath)
        {
            string subKeyName = string.Concat(rootKeyPath, @"\", RunnerRegKeyPrefix + "_Icarus"); // Note: 'Gallio_Icarus' is hardcoded in TDNet's config file.
            string message = "Adding TestDriven.Net runner registry key for Icarus.";

            logger.Log(LogSeverity.Info, message);
            progressMonitor.SetStatus(message);

            using (RegistryKey subKey = hiveKey.CreateSubKey(subKeyName, RegistryKeyPermissionCheck.ReadWriteSubTree))
            {
                subKey.SetValue(null, "1");
                subKey.SetValue("Application", icarusPath);
            }
        }
Пример #33
0
        private void RemoveExistingRegistryKeys(IProgressMonitor progressMonitor, RegistryKey hiveKey, string rootKeyPath)
        {
            using (RegistryKey rootKey = hiveKey.OpenSubKey(rootKeyPath, true))
            {
                if (rootKey == null)
                    return;

                foreach (string subKeyName in rootKey.GetSubKeyNames())
                {
                    if (subKeyName.StartsWith(RunnerRegKeyPrefix))
                    {
                        string message = string.Format("Deleting TestDriven.Net runner registry key '{0}'.", subKeyName);

                        logger.Log(LogSeverity.Info, message);
                        progressMonitor.SetStatus(message);

                        rootKey.DeleteSubKeyTree(subKeyName);
                    }
                }
            }
        }
Пример #34
0
        private void ExploreOrRun(ITestIsolationContext testIsolationContext, TestPackage testPackage, TestExplorationOptions testExplorationOptions,
            TestExecutionOptions testExecutionOptions, IMessageSink messageSink, IProgressMonitor progressMonitor, string taskName)
        {
            using (progressMonitor.BeginTask(taskName, 1))
            {
                if (progressMonitor.IsCanceled)
                    return;

                FileInfo testDriverScriptFile = GetTestDriverScriptFile(testPackage);
                if (testDriverScriptFile == null)
                    return;

                HostSetup hostSetup = CreateHostSetup(testPackage);
                ScriptRuntimeSetup scriptRuntimeSetup = CreateScriptRuntimeSetup(testPackage);
                string testDriverScriptPath = testDriverScriptFile.FullName;
                var remoteMessageSink = new RemoteMessageSink(messageSink);
                var remoteLogger = new RemoteLogger(logger);

                using (var remoteProgressMonitor = new RemoteProgressMonitor(progressMonitor.CreateSubProgressMonitor(1)))
                {
                    testIsolationContext.RunIsolatedTask<ExploreOrRunTask>(hostSetup,
                        (statusMessage) => progressMonitor.SetStatus(statusMessage),
                        new object[] { testPackage, scriptRuntimeSetup, testDriverScriptPath, testExplorationOptions, testExecutionOptions,
                            remoteMessageSink, remoteProgressMonitor, remoteLogger });
                }
            }
        }
 public override void OnContextStart(ContextInfo context)
 {
     _listener.OnContextStart(context);
     _testContext.LifecyclePhase = LifecyclePhases.Starting;
     _progressMonitor.SetStatus(context.FullName);
 }
Пример #36
0
        /// <inheritdoc />
        sealed protected override void RunAssembly(Assembly assembly, TestExplorationOptions testExplorationOptions, TestExecutionOptions testExecutionOptions, IMessageSink messageSink, IProgressMonitor progressMonitor)
        {
            using (progressMonitor.BeginTask(string.Format("Running {0} tests.", FrameworkName), 100))
            {
                using (TestHarness testHarness = CreateTestHarness())
                {
                    IDisposable appDomainState = null;
                    try
                    {
                        progressMonitor.SetStatus("Setting up the test harness.");
                        appDomainState = testHarness.SetUpAppDomain();
                        progressMonitor.Worked(1);

                        progressMonitor.SetStatus("Building the test model.");
                        TestModel testModel = GenerateTestModel(assembly, messageSink);
                        progressMonitor.Worked(3);

                        progressMonitor.SetStatus("Building the test commands.");
                        ITestContextManager testContextManager = CreateTestContextManager(messageSink);
                        ITestCommand        rootTestCommand    = GenerateCommandTree(testModel, testExecutionOptions, testContextManager);
                        progressMonitor.Worked(2);

                        progressMonitor.SetStatus("Running the tests.");
                        if (rootTestCommand != null)
                        {
                            RunTestCommandsAction action = new RunTestCommandsAction(this, rootTestCommand, testExecutionOptions,
                                                                                     testHarness, testContextManager, progressMonitor.CreateSubProgressMonitor(93));

                            if (testExecutionOptions.SingleThreaded)
                            {
                                // The execution options require the use of a single thread.
                                action.Run();
                            }
                            else
                            {
                                // Create a new thread so that we can consistently set the default apartment
                                // state to STA and so as to reduce the effective stack depth during the
                                // test run.  We use Thread instead of ThreadTask because we do not
                                // require the ability to abort the Thread so we do not need to take the
                                // extra overhead.
                                Thread thread = new Thread(action.Run);
                                thread.Name = "Simple Test Driver";
                                thread.SetApartmentState(ApartmentState.STA);
                                thread.Start();
                                thread.Join();
                            }

                            if (action.Exception != null)
                            {
                                throw new ModelException("A fatal exception occurred while running test commands.", action.Exception);
                            }
                        }
                        else
                        {
                            progressMonitor.Worked(93);
                        }
                    }
                    finally
                    {
                        progressMonitor.SetStatus("Tearing down the test harness.");
                        if (appDomainState != null)
                        {
                            appDomainState.Dispose();
                        }
                        progressMonitor.Worked(1);
                    }
                }
            }
        }
Пример #37
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);
                }
            }
        }
Пример #38
0
 /// <inheritdoc />
 protected override sealed void DescribeImpl(IReflectionPolicy reflectionPolicy, IList<ICodeElementInfo> codeElements, TestExplorationOptions testExplorationOptions, IMessageSink messageSink, IProgressMonitor progressMonitor)
 {
     using (progressMonitor.BeginTask(string.Format("Describing {0} tests.", FrameworkName), 100))
     {
         progressMonitor.SetStatus("Building the test model.");
         GenerateTestModel(reflectionPolicy, codeElements, messageSink);
     }
 }
Пример #39
0
 private TestResult RunTest(ITestCommand testCommand, TestStep parentTestStep, IProgressMonitor progressMonitor)
 {
     Test test = testCommand.Test;
     progressMonitor.SetStatus(test.Name);
     var mbUnitCppTest = test as MbUnitCppTest;
     return ((mbUnitCppTest == null) || mbUnitCppTest.TestInfoData.HasChildren)
         ? RunChildTests(testCommand, parentTestStep, progressMonitor)
         : RunTestStep(testCommand, mbUnitCppTest.TestInfoData, parentTestStep, progressMonitor);
 }
Пример #40
0
        /// <inheritdoc />
        public void SaveReport(AttachmentContentDisposition attachmentContentDisposition,
            IProgressMonitor progressMonitor)
        {
            if (progressMonitor == null)
                throw new ArgumentNullException(@"progressMonitor");

            if (reportSaved)
                return;

            int attachmentCount = CountAttachments(report);
            using (progressMonitor.BeginTask("Saving report.", attachmentCount + 1))
            {
                var encoding = new UTF8Encoding(false);
                var settings = new XmlWriterSettings();
                settings.CheckCharacters = false;
                settings.Indent = true;
                settings.Encoding = encoding;
                settings.CloseOutput = true;

                string reportPath = reportContainer.ReportName + @".xml";

                progressMonitor.ThrowIfCanceled();
                progressMonitor.SetStatus(reportPath);

                using (XmlWriter writer = XmlWriter.Create(reportContainer.OpenWrite(reportPath, MimeTypes.Xml, settings.Encoding), settings))
                {
                    progressMonitor.ThrowIfCanceled();
                    SerializeReport(writer, attachmentContentDisposition);
                }

                progressMonitor.Worked(1);
                progressMonitor.SetStatus(@"");

                if (attachmentContentDisposition == AttachmentContentDisposition.Link && attachmentCount != 0)
                {
                    progressMonitor.ThrowIfCanceled();
                    using (IProgressMonitor subProgressMonitor = progressMonitor.CreateSubProgressMonitor(attachmentCount))
                        SaveReportAttachments(subProgressMonitor);
                }

                AddReportDocumentPath(reportPath);
                reportSaved = true;
            }
        }
Пример #41
0
        /// <inheritdoc />
        public void LoadReportAttachments(Report report, IProgressMonitor progressMonitor)
        {
            if (progressMonitor == null)
                throw new ArgumentNullException(@"progressMonitor");

            if (report.TestPackageRun == null)
                return;

            var attachmentsToLoad = new List<AttachmentData>();
            foreach (TestStepRun testStepRun in report.TestPackageRun.AllTestStepRuns)
            {
                foreach (AttachmentData attachment in testStepRun.TestLog.Attachments)
                {
                    if (attachment.ContentPath != null)
                        attachmentsToLoad.Add(attachment);
                }
            }

            if (attachmentsToLoad.Count == 0)
                return;

            using (progressMonitor.BeginTask("Loading report attachments.", attachmentsToLoad.Count))
            {
                foreach (AttachmentData attachment in attachmentsToLoad)
                {
                    progressMonitor.ThrowIfCanceled();

                    if (attachment.ContentDisposition != AttachmentContentDisposition.Link
                        || attachment.ContentPath == null)
                        continue;

                    string attachmentPath = attachment.ContentPath;

                    progressMonitor.SetStatus(attachmentPath);
                    LoadAttachmentContents(attachment, attachmentPath);
                }
            }
        }
Пример #42
0
        /// <inheritdoc />
        protected override sealed void RunAssembly(Assembly assembly, TestExplorationOptions testExplorationOptions, TestExecutionOptions testExecutionOptions, IMessageSink messageSink, IProgressMonitor progressMonitor)
        {
            using (progressMonitor.BeginTask(string.Format("Running {0} tests.", FrameworkName), 100))
            {
                using (TestHarness testHarness = CreateTestHarness())
                {
                    IDisposable appDomainState = null;
                    try
                    {
                        progressMonitor.SetStatus("Setting up the test harness.");
                        appDomainState = testHarness.SetUpAppDomain();
                        progressMonitor.Worked(1);

                        progressMonitor.SetStatus("Building the test model.");
                        TestModel testModel = GenerateTestModel(assembly, messageSink);
                        progressMonitor.Worked(3);

                        progressMonitor.SetStatus("Building the test commands.");
                        ITestContextManager testContextManager = CreateTestContextManager(messageSink);
                        ITestCommand rootTestCommand = GenerateCommandTree(testModel, testExecutionOptions, testContextManager);
                        progressMonitor.Worked(2);

                        progressMonitor.SetStatus("Running the tests.");
                        if (rootTestCommand != null)
                        {
                            RunTestCommandsAction action = new RunTestCommandsAction(this, rootTestCommand, testExecutionOptions,
                                testHarness, testContextManager, progressMonitor.CreateSubProgressMonitor(93));

                            if (testExecutionOptions.SingleThreaded)
                            {
                                // The execution options require the use of a single thread.
                                action.Run();
                            }
                            else
                            {
                                // Create a new thread so that we can consistently set the default apartment
                                // state to STA and so as to reduce the effective stack depth during the
                                // test run.  We use Thread instead of ThreadTask because we do not
                                // require the ability to abort the Thread so we do not need to take the
                                // extra overhead.
                                Thread thread = new Thread(action.Run);
                                thread.Name = "Simple Test Driver";
                                thread.SetApartmentState(ApartmentState.STA);
                                thread.Start();
                                thread.Join();
                            }

                            if (action.Exception != null)
                                throw new ModelException("A fatal exception occurred while running test commands.", action.Exception);
                        }
                        else
                        {
                            progressMonitor.Worked(93);
                        }
                    }
                    finally
                    {
                        progressMonitor.SetStatus("Tearing down the test harness.");
                        if (appDomainState != null)
                            appDomainState.Dispose();
                        progressMonitor.Worked(1);
                    }
                }
            }
        }
Пример #43
0
        /// <inheritdoc />
        protected override sealed void ExploreAssembly(Assembly assembly, TestExplorationOptions testExplorationOptions, IMessageSink messageSink, IProgressMonitor progressMonitor)
        {
            using (progressMonitor.BeginTask(string.Format("Exploring {0} tests.", FrameworkName), 5))
            {
                using (TestHarness testHarness = CreateTestHarness())
                {
                    IDisposable appDomainState = null;
                    try
                    {
                        progressMonitor.SetStatus("Setting up the test harness.");
                        appDomainState = testHarness.SetUpAppDomain();
                        progressMonitor.Worked(1);

                        progressMonitor.SetStatus("Building the test model.");
                        GenerateTestModel(assembly, messageSink);
                        progressMonitor.Worked(3);
                    }
                    finally
                    {
                        progressMonitor.SetStatus("Tearing down the test harness.");
                        if (appDomainState != null)
                            appDomainState.Dispose();
                        progressMonitor.Worked(1);
                    }
                }
            }
        }
Пример #44
0
        private void InstallRegistryKeysForFramework(string frameworkName, AssemblySignature frameworkAssembly, int priority, IProgressMonitor progressMonitor, RegistryKey hiveKey, string rootKeyPath)
        {
            string subKeyName = string.Concat(rootKeyPath, @"\", RunnerRegKeyPrefix, " - ", frameworkName, " (", frameworkAssembly, ")");
            string message = string.Format("Adding TestDriven.Net runner registry key for framework '{0}'.", frameworkName);

            logger.Log(LogSeverity.Info, message);
            progressMonitor.SetStatus(message);

            using (RegistryKey subKey = hiveKey.CreateSubKey(subKeyName, RegistryKeyPermissionCheck.ReadWriteSubTree))
            {
                subKey.SetValue(null, priority.ToString());
                subKey.SetValue("AssemblyPath", AssemblyUtils.GetAssemblyLocalPath(GetType().Assembly));
                subKey.SetValue("TargetFrameworkAssemblyName", frameworkAssembly.ToString()); // n.b. TDNet supports version ranges in the same format we use
                subKey.SetValue("TypeName", "Gallio.TDNetRunner.GallioTestRunner");
                subKey.SetValue("TypeName_Resident", "Gallio.TDNetRunner.GallioResidentTestRunner");
            }
        }
Пример #45
0
        /// <inheritdoc />
        public void SaveReportAttachments(IProgressMonitor progressMonitor)
        {
            if (progressMonitor == null)
                throw new ArgumentNullException(@"progressMonitor");

            if (reportAttachmentsSaved)
                return;

            int attachmentCount = CountAttachments(report);
            if (attachmentCount == 0)
                return;

            using (progressMonitor.BeginTask("Saving report attachments.", attachmentCount))
            {
                foreach (TestStepRun testStepRun in report.TestPackageRun.AllTestStepRuns)
                {
                    foreach (AttachmentData attachment in testStepRun.TestLog.Attachments)
                    {
                        string attachmentPath = attachmentPathResolver.GetAttachmentPath(testStepRun.Step.Id, attachment.Name, attachment.ContentType);

                        progressMonitor.ThrowIfCanceled();
                        progressMonitor.SetStatus(attachmentPath);

                        SaveAttachmentContents(attachment, attachmentPath);

                        progressMonitor.Worked(1);
                    }
                }

                reportAttachmentsSaved = true;
            }
        }
Пример #46
0
        /// <inheritdoc />
        public override void Format(IReportWriter reportWriter, ReportFormatterOptions options, IProgressMonitor progressMonitor)
        {
            AttachmentContentDisposition attachmentContentDisposition = GetAttachmentContentDisposition(options);

            using (progressMonitor.BeginTask("Formatting report.", 10))
            {
                progressMonitor.SetStatus("Applying XSL transform.");
                ApplyTransform(reportWriter, attachmentContentDisposition, options);
                progressMonitor.Worked(3);

                progressMonitor.SetStatus("Copying resources.");
                CopyResources(reportWriter);
                progressMonitor.Worked(2);

                progressMonitor.SetStatus(@"");

                if (attachmentContentDisposition == AttachmentContentDisposition.Link)
                {
                    using (IProgressMonitor subProgressMonitor = progressMonitor.CreateSubProgressMonitor(5))
                        reportWriter.SaveReportAttachments(subProgressMonitor);
                }
            }
        }
            private void Initialize()
            {
                progressMonitor.Canceled += HandleCanceled;
                progressMonitor.SetStatus(Resources.MbUnit2TestController_InitializingMbUnitTestRunner);

                int totalWork = 1;

                if (fixtureExplorer.HasAssemblySetUp)
                {
                    totalWork += 1;
                }
                if (fixtureExplorer.HasAssemblyTearDown)
                {
                    totalWork += 1;
                }

                // Build a reverse mapping from types and run-pipes to tests.
                includedFixtureTypes = new HashSet <Type>();
                fixtureTestCommands  = new Dictionary <Fixture, ITestCommand>();
                runPipeTestCommands  = new Dictionary <RunPipe, ITestCommand>();
                activeTestContexts   = new Dictionary <ITestCommand, ITestContext>();

                bool isExplicit = false;

                foreach (ITestCommand testCommand in testCommands)
                {
                    if (testCommand.IsExplicit)
                    {
                        isExplicit = true;
                    }

                    MbUnit2Test test    = (MbUnit2Test)testCommand.Test;
                    Fixture     fixture = test.Fixture;
                    RunPipe     runPipe = test.RunPipe;

                    if (fixture == null)
                    {
                        assemblyTestCommand = testCommand;
                    }
                    else if (runPipe == null)
                    {
                        includedFixtureTypes.Add(fixture.Type);
                        fixtureTestCommands[fixture] = testCommand;

                        if (fixture.HasSetUp)
                        {
                            totalWork += 1;
                        }
                        if (fixture.HasTearDown)
                        {
                            totalWork += 1;
                        }
                    }
                    else
                    {
                        runPipeTestCommands[runPipe] = testCommand;
                        totalWork += 1;
                    }
                }

                // Set options
                IsExplicit    = isExplicit;
                FixtureFilter = this;
                RunPipeFilter = this;

                workUnit = 1.0 / totalWork;
                progressMonitor.Worked(workUnit);
            }
Пример #48
0
        /// <inheritdoc />
        public void Initialize(TestRunnerOptions testRunnerOptions, ILogger logger, IProgressMonitor progressMonitor)
        {
            if (testRunnerOptions == null)
            {
                throw new ArgumentNullException("testRunnerOptions");
            }
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }
            if (progressMonitor == null)
            {
                throw new ArgumentNullException("progressMonitor");
            }

            ThrowIfDisposed();
            if (state != State.Created)
            {
                throw new InvalidOperationException("The test runner has already been initialized.");
            }

            testRunnerOptions = testRunnerOptions.Copy();

            this.testRunnerOptions = testRunnerOptions;
            tappedLogger           = new TappedLogger(this, logger);

            int extensionCount = extensions.Count;

            using (progressMonitor.BeginTask("Initializing the test runner.", 1 + extensionCount))
            {
                foreach (ITestRunnerExtension extension in extensions)
                {
                    string extensionName = extension.GetType().Name; // TODO: improve me

                    progressMonitor.SetStatus(String.Format("Installing extension '{0}'.", extensionName));
                    try
                    {
                        // Note: We don't pass the tapped logger to the extensions because the
                        //       extensions frequently write to the console a bunch of information we
                        //       already have represented in the report.  We are more interested in what
                        //       the test driver has to tell us.
                        extension.Install(eventDispatcher, logger);
                        progressMonitor.Worked(1);
                    }
                    catch (Exception ex)
                    {
                        throw new RunnerException(String.Format("Failed to install extension '{0}'.", extensionName), ex);
                    }
                    progressMonitor.SetStatus("");
                }

                try
                {
                    UnhandledExceptionPolicy.ReportUnhandledException += OnUnhandledException;

                    eventDispatcher.NotifyInitializeStarted(new InitializeStartedEventArgs(testRunnerOptions));

                    progressMonitor.SetStatus("Initializing the test isolation context.");

                    TestIsolationOptions testIsolationOptions = new TestIsolationOptions();
                    GenericCollectionUtils.ForEach(testRunnerOptions.Properties, x => testIsolationOptions.AddProperty(x.Key, x.Value));
                    testIsolationContext = testIsolationProvider.CreateContext(testIsolationOptions, tappedLogger);

                    progressMonitor.Worked(1);
                }
                catch (Exception ex)
                {
                    eventDispatcher.NotifyInitializeFinished(new InitializeFinishedEventArgs(false));

                    UnhandledExceptionPolicy.ReportUnhandledException -= OnUnhandledException;

                    throw new RunnerException("A fatal exception occurred while initializing the test isolation context.", ex);
                }

                state = State.Initialized;
                eventDispatcher.NotifyInitializeFinished(new InitializeFinishedEventArgs(true));
            }
        }
Пример #49
0
        private void ExploreOrRun(ITestIsolationContext testIsolationContext, TestPackage testPackage, TestExplorationOptions testExplorationOptions,
                                  TestExecutionOptions testExecutionOptions, IMessageSink messageSink, IProgressMonitor progressMonitor, string taskName)
        {
            using (progressMonitor.BeginTask(taskName, 1))
            {
                if (progressMonitor.IsCanceled)
                {
                    return;
                }

                FileInfo testDriverScriptFile = GetTestDriverScriptFile(testPackage);
                if (testDriverScriptFile == null)
                {
                    return;
                }

                HostSetup          hostSetup            = CreateHostSetup(testPackage);
                ScriptRuntimeSetup scriptRuntimeSetup   = CreateScriptRuntimeSetup(testPackage);
                string             testDriverScriptPath = testDriverScriptFile.FullName;
                var remoteMessageSink = new RemoteMessageSink(messageSink);
                var remoteLogger      = new RemoteLogger(logger);

                using (var remoteProgressMonitor = new RemoteProgressMonitor(progressMonitor.CreateSubProgressMonitor(1)))
                {
                    testIsolationContext.RunIsolatedTask <ExploreOrRunTask>(hostSetup,
                                                                            (statusMessage) => progressMonitor.SetStatus(statusMessage),
                                                                            new object[] { testPackage, scriptRuntimeSetup, testDriverScriptPath, testExplorationOptions, testExecutionOptions,
                                                                                           remoteMessageSink, remoteProgressMonitor, remoteLogger });
                }
            }
        }
Пример #50
0
        /// <inheritdoc />
        public void Dispose(IProgressMonitor progressMonitor)
        {
            if (progressMonitor == null)
                throw new ArgumentNullException("progressMonitor");
            if (state == State.Disposed)
                return;

            using (progressMonitor.BeginTask("Disposing the test runner.", 10))
            {
                bool success;
                try
                {
                    eventDispatcher.NotifyDisposeStarted(new DisposeStartedEventArgs());

                    if (testIsolationContext != null)
                    {
                        progressMonitor.SetStatus("Disposing the test isolation context.");

                        testIsolationContext.Dispose();
                        testIsolationContext = null;
                    }

                    progressMonitor.Worked(10);
                    success = true;
                }
                catch (Exception ex)
                {
                    if (tappedLogger != null)
                        tappedLogger.Log(LogSeverity.Warning, "An exception occurred while disposing the test isolation context.  This may indicate that the test isolation context previously encountered another fault from which it could not recover.", ex);
                    success = false;
                }

                state = State.Disposed;
                eventDispatcher.NotifyDisposeFinished(new DisposeFinishedEventArgs(success));

                UnhandledExceptionPolicy.ReportUnhandledException -= OnUnhandledException;
            }
        }
        private TestResult RunTest(ITestCommand testCommand, TestStep parentTestStep,
            TestExecutionOptions options, IProgressMonitor progressMonitor)
        {
            // NOTE: This method has been optimized to minimize the total stack depth of the action
            //       by inlining blocks on the critical path that had previously been factored out.

            using (TestController testController = testControllerProvider(testCommand.Test))
            {
                if (testController != null)
                {
                    try
                    {
                        using (IProgressMonitor subProgressMonitor = progressMonitor.CreateSubProgressMonitor(testCommand.TestCount))
                        {
                            // Calling RunImpl directly instead of Run to minimize stack depth
                            // because we already know the arguments are valid.
                            return testController.RunImpl(testCommand, parentTestStep, options, subProgressMonitor);
                        }
                    }
                    catch (Exception ex)
                    {
                        ITestContext context = testCommand.StartPrimaryChildStep(parentTestStep);
                        context.LogWriter.Failures.WriteException(ex, "Fatal Exception in test controller");
                        return context.FinishStep(TestOutcome.Error, null);
                    }
                }
            }

            // Enter the scope of the test and recurse until we find a controller.
            progressMonitor.SetStatus(testCommand.Test.FullName);

            ITestContext testContext = testCommand.StartPrimaryChildStep(parentTestStep);
            TestOutcome outcome = TestOutcome.Passed;

            foreach (ITestCommand monitor in testCommand.Children)
            {
                if (progressMonitor.IsCanceled)
                    break;

                TestResult childResult = RunTest(monitor, testContext.TestStep, options, progressMonitor);
                outcome = outcome.CombineWith(childResult.Outcome).Generalize();
            }

            if (progressMonitor.IsCanceled)
                outcome = TestOutcome.Canceled;

            TestResult result = testContext.FinishStep(outcome, null);

            progressMonitor.Worked(1);
            return result;
        }
Пример #52
0
 public void SetStatus(string status)
 {
     progressMonitor.SetStatus(status);
 }
Пример #53
0
        /// <inheritdoc />
        public void Initialize(TestRunnerOptions testRunnerOptions, ILogger logger, IProgressMonitor progressMonitor)
        {
            if (testRunnerOptions == null)
                throw new ArgumentNullException("testRunnerOptions");
            if (logger == null)
                throw new ArgumentNullException("logger");
            if (progressMonitor == null)
                throw new ArgumentNullException("progressMonitor");

            ThrowIfDisposed();
            if (state != State.Created)
                throw new InvalidOperationException("The test runner has already been initialized.");

            testRunnerOptions = testRunnerOptions.Copy();

            this.testRunnerOptions = testRunnerOptions;
            tappedLogger = new TappedLogger(this, logger);

            int extensionCount = extensions.Count;
            using (progressMonitor.BeginTask("Initializing the test runner.", 1 + extensionCount))
            {
                foreach (ITestRunnerExtension extension in extensions)
                {
                    string extensionName = extension.GetType().Name; // TODO: improve me

                    progressMonitor.SetStatus(String.Format("Installing extension '{0}'.", extensionName));
                    try
                    {
                        // Note: We don't pass the tapped logger to the extensions because the
                        //       extensions frequently write to the console a bunch of information we
                        //       already have represented in the report.  We are more interested in what
                        //       the test driver has to tell us.
                        extension.Install(eventDispatcher, logger);
                        progressMonitor.Worked(1);
                    }
                    catch (Exception ex)
                    {
                        throw new RunnerException(String.Format("Failed to install extension '{0}'.", extensionName), ex);
                    }
                    progressMonitor.SetStatus("");
                }

                try
                {
                    UnhandledExceptionPolicy.ReportUnhandledException += OnUnhandledException;

                    eventDispatcher.NotifyInitializeStarted(new InitializeStartedEventArgs(testRunnerOptions));

                    progressMonitor.SetStatus("Initializing the test isolation context.");

                    TestIsolationOptions testIsolationOptions = new TestIsolationOptions();
                    GenericCollectionUtils.ForEach(testRunnerOptions.Properties, x => testIsolationOptions.AddProperty(x.Key, x.Value));
                    testIsolationContext = testIsolationProvider.CreateContext(testIsolationOptions, tappedLogger);

                    progressMonitor.Worked(1);
                }
                catch (Exception ex)
                {
                    eventDispatcher.NotifyInitializeFinished(new InitializeFinishedEventArgs(false));

                    UnhandledExceptionPolicy.ReportUnhandledException -= OnUnhandledException;

                    throw new RunnerException("A fatal exception occurred while initializing the test isolation context.", ex);
                }

                state = State.Initialized;
                eventDispatcher.NotifyInitializeFinished(new InitializeFinishedEventArgs(true));
            }
        }