From 31b8346ac5a6caaa9a6c486257d5abd66b6d4b29 Mon Sep 17 00:00:00 2001 From: "pavel.butuzov" Date: Tue, 8 Oct 2024 09:37:21 +0300 Subject: [PATCH 1/2] Fixed filtering by labels with "tmsLabelsOfTestsToRun" parameter. --- Tms.Adapter.Core/Tms.Adapter.Core.csproj | 2 +- .../Tms.Adapter.SpecFlowPlugin.csproj | 2 +- Tms.Adapter.XUnit/Tms.Adapter.XUnit.csproj | 2 +- Tms.Adapter/Tms.Adapter.csproj | 2 +- TmsRunner/App.cs | 2 +- TmsRunner/Services/FilterService.cs | 23 +++++++++++-------- TmsRunner/TmsRunner.csproj | 2 +- TmsRunnerTests/Services/FilterServiceTests.cs | 4 +++- 8 files changed, 22 insertions(+), 17 deletions(-) diff --git a/Tms.Adapter.Core/Tms.Adapter.Core.csproj b/Tms.Adapter.Core/Tms.Adapter.Core.csproj index 25d01a1..3031048 100644 --- a/Tms.Adapter.Core/Tms.Adapter.Core.csproj +++ b/Tms.Adapter.Core/Tms.Adapter.Core.csproj @@ -1,7 +1,7 @@  - 1.6.4 + 1.6.5 netstandard2.1 enable true diff --git a/Tms.Adapter.SpecFlowPlugin/Tms.Adapter.SpecFlowPlugin.csproj b/Tms.Adapter.SpecFlowPlugin/Tms.Adapter.SpecFlowPlugin.csproj index 70cd648..6e74b04 100644 --- a/Tms.Adapter.SpecFlowPlugin/Tms.Adapter.SpecFlowPlugin.csproj +++ b/Tms.Adapter.SpecFlowPlugin/Tms.Adapter.SpecFlowPlugin.csproj @@ -1,7 +1,7 @@  - 1.6.4 + 1.6.5 netstandard2.1 enable true diff --git a/Tms.Adapter.XUnit/Tms.Adapter.XUnit.csproj b/Tms.Adapter.XUnit/Tms.Adapter.XUnit.csproj index b3eaed4..02fa370 100644 --- a/Tms.Adapter.XUnit/Tms.Adapter.XUnit.csproj +++ b/Tms.Adapter.XUnit/Tms.Adapter.XUnit.csproj @@ -1,7 +1,7 @@  - 1.6.4 + 1.6.5 netstandard2.1 enable true diff --git a/Tms.Adapter/Tms.Adapter.csproj b/Tms.Adapter/Tms.Adapter.csproj index 4c95fce..3ed921b 100644 --- a/Tms.Adapter/Tms.Adapter.csproj +++ b/Tms.Adapter/Tms.Adapter.csproj @@ -1,7 +1,7 @@  - 1.6.4 + 1.6.5 netstandard2.1 enable true diff --git a/TmsRunner/App.cs b/TmsRunner/App.cs index cb67a31..bdb914d 100644 --- a/TmsRunner/App.cs +++ b/TmsRunner/App.cs @@ -48,7 +48,7 @@ public async Task RunAsync() if (!string.IsNullOrEmpty(adapterConfig.TmsLabelsOfTestsToRun)) { - testCases = FilterService.FilterTestCasesByLabels(adapterConfig, testCases); + testCases = filterService.FilterTestCasesByLabels(adapterConfig, testCases); } break; diff --git a/TmsRunner/Services/FilterService.cs b/TmsRunner/Services/FilterService.cs index bec19db..ac3c020 100644 --- a/TmsRunner/Services/FilterService.cs +++ b/TmsRunner/Services/FilterService.cs @@ -66,21 +66,26 @@ private string GetExternalId(MethodInfo testMethod, TestCase testCase) return (testMethod.DeclaringType!.FullName + "." + testMethod.Name).ComputeHash(); } - public static List FilterTestCasesByLabels(AdapterConfig config, IReadOnlyCollection testCases) + public List FilterTestCasesByLabels(AdapterConfig config, IReadOnlyCollection testCases) { var labelsToRun = config.TmsLabelsOfTestsToRun?.Split(',').Select(x => x.Trim()).ToList(); var testCasesName = testCases.Select(t => t.FullyQualifiedName); var testCasesToRun = new List(); var assembly = Assembly.LoadFrom(config.TestAssemblyPath ?? string.Empty); - var testMethods = new List( - assembly.GetExportedTypes() - .SelectMany(type => type.GetMethods()) - .Where(m => testCasesName.Contains(m.DeclaringType!.FullName + "." + m.Name)) - ); + var allTestMethods = new List(assembly.GetExportedTypes().SelectMany(type => type.GetMethods())); - foreach (var testMethod in testMethods) + foreach (var testCase in testCases) { - var fullName = testMethod.DeclaringType?.FullName + "." + testMethod.Name; + var testMethod = allTestMethods.FirstOrDefault( + m => (m.DeclaringType!.FullName + "." + m.Name).Contains(ParametersRegex.Replace(testCase.FullyQualifiedName, string.Empty)) + ); + + if (testMethod == null) + { + logger.LogError("TestMethod {@FullyQualifiedName} not found", testCase.FullyQualifiedName); + continue; + } + var customAttributes = testMethod.GetCustomAttributes(false); foreach (var attribute in customAttributes) @@ -89,8 +94,6 @@ public static List FilterTestCasesByLabels(AdapterConfig config, IRead { if (labelsAttr.Value?.Any(x => labelsToRun?.Contains(x) ?? false) ?? false) { - var testCase = testCases.FirstOrDefault(x => x.FullyQualifiedName == fullName); - if (testCase != null) { testCasesToRun.Add(testCase); diff --git a/TmsRunner/TmsRunner.csproj b/TmsRunner/TmsRunner.csproj index 1f4db6e..eb620e8 100644 --- a/TmsRunner/TmsRunner.csproj +++ b/TmsRunner/TmsRunner.csproj @@ -1,7 +1,7 @@  - 1.6.4 + 1.6.5 Exe enable enable diff --git a/TmsRunnerTests/Services/FilterServiceTests.cs b/TmsRunnerTests/Services/FilterServiceTests.cs index 90ef052..4ff064b 100644 --- a/TmsRunnerTests/Services/FilterServiceTests.cs +++ b/TmsRunnerTests/Services/FilterServiceTests.cs @@ -33,6 +33,8 @@ public void FilterTestCases() public void FilterTestCasesByLabels() { // Arrange + var filterService = new FilterService(_logger, _replacer); + var assemblyPath = typeof(FilterServiceTests).Assembly.Location; var config = new AdapterConfig { TestAssemblyPath = typeof(FilterServiceTests).Assembly.Location @@ -40,7 +42,7 @@ public void FilterTestCasesByLabels() var testcases = new[] { new TestCase() }; // Act - var actual = FilterService.FilterTestCasesByLabels(config, testcases); + var actual = filterService.FilterTestCasesByLabels(config, testcases); // Assert Assert.AreEqual(0, actual.Count); From 55265c384d7154463981a6881e6d6b04d70ebb86 Mon Sep 17 00:00:00 2001 From: "pavel.butuzov" Date: Tue, 8 Oct 2024 09:53:40 +0300 Subject: [PATCH 2/2] Fixed the tests. --- TmsRunner/Services/FilterService.cs | 1 - TmsRunnerTests/Services/FilterServiceTests.cs | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/TmsRunner/Services/FilterService.cs b/TmsRunner/Services/FilterService.cs index ac3c020..9be0e9a 100644 --- a/TmsRunner/Services/FilterService.cs +++ b/TmsRunner/Services/FilterService.cs @@ -69,7 +69,6 @@ private string GetExternalId(MethodInfo testMethod, TestCase testCase) public List FilterTestCasesByLabels(AdapterConfig config, IReadOnlyCollection testCases) { var labelsToRun = config.TmsLabelsOfTestsToRun?.Split(',').Select(x => x.Trim()).ToList(); - var testCasesName = testCases.Select(t => t.FullyQualifiedName); var testCasesToRun = new List(); var assembly = Assembly.LoadFrom(config.TestAssemblyPath ?? string.Empty); var allTestMethods = new List(assembly.GetExportedTypes().SelectMany(type => type.GetMethods())); diff --git a/TmsRunnerTests/Services/FilterServiceTests.cs b/TmsRunnerTests/Services/FilterServiceTests.cs index 4ff064b..87cd9ec 100644 --- a/TmsRunnerTests/Services/FilterServiceTests.cs +++ b/TmsRunnerTests/Services/FilterServiceTests.cs @@ -34,12 +34,11 @@ public void FilterTestCasesByLabels() { // Arrange var filterService = new FilterService(_logger, _replacer); - var assemblyPath = typeof(FilterServiceTests).Assembly.Location; var config = new AdapterConfig { TestAssemblyPath = typeof(FilterServiceTests).Assembly.Location }; - var testcases = new[] { new TestCase() }; + var testcases = new[] { new TestCase { FullyQualifiedName = "test" } }; // Act var actual = filterService.FilterTestCasesByLabels(config, testcases);