public void RunTests(IEnumerable <TestCase> tests, IRunContext runContext, IFrameworkHandle frameworkHandle) { // more on filtering // https://github.com/nunit/nunit3-vs-adapter/blob/master/src/NUnitTestAdapter/VsTestFilter.cs List <string> supportedProperties = new List <string>(); supportedProperties.Add("FullyQualifiedName"); ITestCaseFilterExpression fe = runContext.GetTestCaseFilter(supportedProperties, PropertyProvider); log.Debug("Run settings:\n" + runContext.RunSettings.SettingsXml); log.Debug("RunTests from Test Cases"); foreach (TestCase tc in tests) { if (fe == null || fe.MatchTestCase(tc, p => PropertyValueProvider(tc, p))) { log.Debug("Run test case: " + tc.FullyQualifiedName + " / " + tc.Id); frameworkHandle.RecordStart(tc); DateTime startTime = DateTime.Now; TestResult tr = runner.RunTest(tc, runContext); DateTime endTime = DateTime.Now; tr.Duration = endTime - startTime; frameworkHandle.RecordEnd(tc, tr.Outcome); frameworkHandle.RecordResult(tr); } else { log.Debug("Test case filtered out: " + tc.FullyQualifiedName + " / " + tc.Id); } } }
private static bool MatchTestFilter(ITestCaseFilterExpression filterExpression, TestCase test, TestMethodFilter testMethodFilter) { if (filterExpression != null && filterExpression.MatchTestCase(test, p => testMethodFilter.PropertyValueProvider(test, p)) == false) { // Skip test if not fitting filter criteria. return(false); } return(true); }
private bool Matches(TestCase testCase, ITestCaseFilterExpression filterExpression) { bool matches = filterExpression.MatchTestCase(testCase, propertyName => PropertyValueProvider(testCase, propertyName)); string message = matches ? $"{testCase.DisplayName} matches {filterExpression.TestCaseFilterValue}" : $"{testCase.DisplayName} does not match {filterExpression.TestCaseFilterValue}"; _testEnvironment.DebugInfo(message); return(matches); }
private bool Matches(TestCase testCase, ITestCaseFilterExpression filterExpression) { bool matches = filterExpression.MatchTestCase(testCase, propertyName => PropertyValueProvider(testCase, propertyName)); string message = matches ? String.Format(Resources.Matches, testCase.DisplayName, filterExpression.TestCaseFilterValue) : String.Format(Resources.DoesntMatch, testCase.DisplayName, filterExpression.TestCaseFilterValue); _logger.DebugInfo(message); return(matches); }
public bool MatchTestCase(TestCase testCase) { if (!successfullyGotFilter) { // Had an error while getting filter, match no testcase to ensure discovered test list is empty return(false); } else if (filterExpression == null) { // No filter specified, keep every testcase return(true); } return(filterExpression.MatchTestCase(testCase, (p) => PropertyProvider(testCase, p))); }
public IEnumerable <TestCase> GetFilteredTestList(IEnumerable <TestCase> testCases, IRunContext runContext, LoggerHelper logger, string assemblyFileName) { ITestCaseFilterExpression filter = null; if (GetTestCaseFilterExpression(runContext, logger, assemblyFileName, out filter)) { if (filter != null) { return(testCases.Where(testCase => filter.MatchTestCase(testCase, (p) => PropertyProvider(testCase, p)))); } } else { // Error while filtering, ensure discovered test list is empty return(Enumerable.Empty <TestCase>()); } // No filter is specified return the original list return(testCases); }
internal void SendTestCases(string source, IEnumerable <UnitTestElement> testElements, ITestCaseDiscoverySink discoverySink, IDiscoveryContext discoveryContext, IMessageLogger logger) { var shouldCollectSourceInformation = MSTestSettings.RunConfigurationSettings.CollectSourceInformation; var navigationSessions = new Dictionary <string, object>(); try { if (shouldCollectSourceInformation) { navigationSessions.Add(source, PlatformServiceProvider.Instance.FileOperations.CreateNavigationSession(source)); } // Get filter expression and skip discovery in case filter expression has parsing error. ITestCaseFilterExpression filterExpression = this.TestMethodFilter.GetFilterExpression(discoveryContext, logger, out var filterHasError); if (filterHasError) { return; } foreach (var testElement in testElements) { var testCase = testElement.ToTestCase(); // Filter tests based on test case filters if (filterExpression != null && filterExpression.MatchTestCase(testCase, (p) => this.TestMethodFilter.PropertyValueProvider(testCase, p)) == false) { continue; } if (shouldCollectSourceInformation) { string testSource = testElement.TestMethod.DeclaringAssemblyName ?? source; if (!navigationSessions.TryGetValue(testSource, out var testNavigationSession)) { testNavigationSession = PlatformServiceProvider.Instance.FileOperations.CreateNavigationSession(testSource); navigationSessions.Add(testSource, testNavigationSession); } if (testNavigationSession != null) { var className = testElement.TestMethod.DeclaringClassFullName ?? testElement.TestMethod.FullClassName; var methodName = testElement.TestMethod.Name; // If it is async test method use compiler generated type and method name for navigation data. if (!string.IsNullOrEmpty(testElement.AsyncTypeName)) { className = testElement.AsyncTypeName; // compiler generated method name is "MoveNext". methodName = "MoveNext"; } PlatformServiceProvider.Instance.FileOperations.GetNavigationData( testNavigationSession, className, methodName, out var minLineNumber, out var fileName); if (!string.IsNullOrEmpty(fileName)) { testCase.LineNumber = minLineNumber; testCase.CodeFilePath = fileName; } } } discoverySink.SendTestCase(testCase); } } finally { foreach (object navigationSession in navigationSessions.Values) { PlatformServiceProvider.Instance.FileOperations.DisposeNavigationSession(navigationSession); } } }
private bool Matches(TestCase testCase, ITestCaseFilterExpression filterExpression) { bool matches = filterExpression.MatchTestCase(testCase, propertyName => PropertyValueProvider(testCase, propertyName)); string message = matches ? $"{testCase.DisplayName} matches {filterExpression.TestCaseFilterValue}" : $"{testCase.DisplayName} does not match {filterExpression.TestCaseFilterValue}"; _testEnvironment.DebugInfo(message); return matches; }