예제 #1
0
        /// <summary>
        /// Invokes the editor for the specified Gallio test.
        /// </summary>
        /// <param name="uiBlob">Identifies the Project/Item blob to be displayed.</param>
        /// <param name="test">The test that the editor is being invoked for.</param>
        public void InvokeEditor(UIBlob uiBlob, ITestElement test)
        {
            if (!TipShellExtension.IsInitialized)
            {
                return;
            }

            GallioTestElement gallioTest = test as GallioTestElement;

            if (gallioTest != null)
            {
                if (gallioTest.Path == null)
                {
                    ErrorDialog.Show(NativeWindow.FromHandle((IntPtr)dte.MainWindow.HWnd),
                                     Properties.Resources.UnknownTestCodeLocationCaption,
                                     Properties.Resources.UnknownTestCodeLocation,
                                     "");
                }
                else
                {
                    Window window = dte.OpenFile(EnvDTE.Constants.vsViewKindCode, gallioTest.Path);

                    TextSelection selection = window.Selection as TextSelection;
                    if (gallioTest.Line != 0)
                    {
                        if (selection != null)
                        {
                            selection.MoveToLineAndOffset(gallioTest.Line, Math.Max(1, gallioTest.Column), false);
                        }
                    }

                    window.Activate();
                }
            }
        }
예제 #2
0
        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());
            }
        }
예제 #3
0
 public GallioTestElement(GallioTestElement element)
     : base(element)
 {
     gallioTestId  = element.gallioTestId;
     assemblyName  = element.assemblyName;
     namespaceName = element.namespaceName;
     typeName      = element.typeName;
     memberName    = element.memberName;
     parameterName = element.parameterName;
     path          = element.path;
     line          = element.line;
     column        = element.column;
 }
예제 #4
0
 public GallioTestElement(GallioTestElement element)
     : base(element)
 {
     gallioTestId = element.gallioTestId;
     assemblyName = element.assemblyName;
     namespaceName = element.namespaceName;
     typeName = element.typeName;
     memberName = element.memberName;
     parameterName = element.parameterName;
     path = element.path;
     line = element.line;
     column = element.column;
 }
예제 #5
0
        public static GallioTestElement CreateTestElement(TestData test, string assemblyPath, ProjectData projectData)
        {
            GallioTestElement testElement = new GallioTestElement(test.Id, test.Name,
                test.Metadata.GetValue(MetadataKeys.Description) ?? "", assemblyPath);
            testElement.ProjectData = projectData;

            foreach (KeyValuePair<string, IList<string>> pair in test.Metadata)
                testElement.Properties[pair.Key] = pair.Value.Count == 1 ? (object)pair.Value[0] : pair.Value;

            testElement.Owner = test.Metadata.GetValue(MetadataKeys.AuthorName) ?? "";

            testElement.SetCodeReference(test.CodeReference.AssemblyName, test.CodeReference.NamespaceName,
                test.CodeReference.TypeName, test.CodeReference.MemberName, test.CodeReference.ParameterName);
            testElement.SetCodeLocation(test.CodeLocation.Path, test.CodeLocation.Line, test.CodeLocation.Column);

            testElement.Timeout = 0; // disable Visual Studio's built-in timeout handling, Gallio manages its own timeouts
            return testElement;
        }
예제 #6
0
        protected override void Initialize()
        {
            foreach (ITestElement testElement in runContext.RunConfig.TestElements)
            {
                GallioTestElement gallioTestElement = testElement as GallioTestElement;
                if (gallioTestElement != null)
                {
                    testElementsById.Add(gallioTestElement.GallioTestId, gallioTestElement);
                }
            }

            Events.RunStarted += delegate(object sender, RunStartedEventArgs e)
            {
                // Change the status of all tests to Started so that all Gallio tests look "In Progress".
                // If we didn't do this, then there would be one "In Progress" test (the first one started)
                // and a whole bunch of "Pending" tests.  Visual Studio assumes that it controls the order
                // of execution of all tests but it cannot.  Behind the scenes we hijack the order of execution
                // when Visual Studio starts the first test.  Of course that test might not actually run
                // first but it will seem to be "In Progress" just the same.  Instead of misleading the user
                // as to which test is currently running, we just make them all look "In Progress" at once.  Ugh.
                foreach (GallioTestElement gallioTestElement in testElementsById.Values)
                {
                    TestStateEvent ev = new TestStateEvent(runContext.RunConfig.TestRun.Id, gallioTestElement.ExecutionId.Id, TestState.Started);
                    runContext.ResultSink.AddResult(ev);
                }
            };

            Events.TestStepFinished += delegate(object sender, TestStepFinishedEventArgs e)
            {
                // Submit a GallioTestResult for each primary run of a test case.
                // In the case of data-driven tests, we may submit multiple results that will later be merged.
                if (e.TestStepRun.Step.IsPrimary)
                {
                    GallioTestElement gallioTestElement = GetTestElement(e.Test);
                    if (gallioTestElement != null)
                    {
                        GallioTestResult result = GallioTestResultFactory.CreateTestResult(e.TestStepRun, runContext.RunConfig.TestRun.Id, gallioTestElement);
                        runContext.ResultSink.AddResult(result);
                    }
                }
            };
        }