Beispiel #1
0
        public void Prepare(Project testProject, ConfigurationSelector configuration)
        {
            var unitTestDll           = testProject.GetOutputFileName(configuration).ToString();
            var instrumentationHelper = new InstrumentationHelper(new ProcessExitHandler(), new RetryHelper(), fileSystem);
            var coverage = new CoverletCoverage(unitTestDll,
                                                new string[0], // Include Filters
                                                new string[0], // Include directories
                                                new string[0], // Exclude Filters
                                                new string[0], // Excluded Source Files
                                                new string[0], // Exclude Attributes
                                                false,         // Include test assembly
                                                false,         // Single hit
                                                null,          // Merge with
                                                false,         // Use source link
                                                logger,
                                                instrumentationHelper,
                                                fileSystem);

            coverage.PrepareModules();
            projectCoverageMap[new Tuple <Project, ConfigurationSelector>(testProject, configuration)] = coverage;
        }
        public static void OnTestExecutionStarting(object sender, OperationStateChangedEventArgs stateArgs)
        {
            _coverageSession = new Dictionary <string, Coverlet.Core.Coverage>();

            // You can get this lovely DLL in your visual studio directory Microsoft.VisualStudio.TestWindow.Core.dll
            // var g = ((Microsoft.VisualStudio.TestWindow.Controller.Request)stateArgs.Operation);
            // If you know a better to get the actual "DLL path" without doing a Directory.Get files.. please let me know

            try
            {
                // This works for VS2017 but not for 2019 due to them sealing the DLL's
                // Track this for the fix https://github.com/ppumkin/PrestoCoverage/issues/17


                var testRequestConfiguration = stateArgs.Operation.GetType()
                                               .GetProperty("Configuration", BindingFlags.NonPublic | BindingFlags.Instance)
                                               .GetValue(stateArgs.Operation) as Microsoft.VisualStudio.TestWindow.Controller.TestRunConfiguration;

                if (testRequestConfiguration.Debug)
                {
                    return;
                }

                foreach (var testDll in testRequestConfiguration.TestSources)
                {
                    //Hacky McHack face here. lots of cool settings and stuff we can expand on but this just gets it going bare bones
                    var _coverage = new Coverlet.Core.Coverage(testDll, new string[0], new string[0], new string[0], new string[0],
                                                               new string[0], true, string.Empty, false, null);

                    _coverage.PrepareModules();

                    _coverageSession.Add(testDll, _coverage);
                }
            }
            catch (Exception ex)
            {
                return;
            }
        }