Skip to content

Commit

Permalink
Merge pull request #63 from testit-tms/hotfix/fix_filtering_by_labels
Browse files Browse the repository at this point in the history
Fixed filtering by labels with "tmsLabelsOfTestsToRun" parameter.
  • Loading branch information
PavelButuzov authored Oct 8, 2024
2 parents b360155 + 55265c3 commit 56a71ca
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Tms.Adapter.Core/Tms.Adapter.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.6.4</Version>
<Version>1.6.5</Version>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.6.4</Version>
<Version>1.6.5</Version>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
Expand Down
2 changes: 1 addition & 1 deletion Tms.Adapter.XUnit/Tms.Adapter.XUnit.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.6.4</Version>
<Version>1.6.5</Version>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
Expand Down
2 changes: 1 addition & 1 deletion Tms.Adapter/Tms.Adapter.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.6.4</Version>
<Version>1.6.5</Version>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
Expand Down
2 changes: 1 addition & 1 deletion TmsRunner/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task<int> RunAsync()

if (!string.IsNullOrEmpty(adapterConfig.TmsLabelsOfTestsToRun))
{
testCases = FilterService.FilterTestCasesByLabels(adapterConfig, testCases);
testCases = filterService.FilterTestCasesByLabels(adapterConfig, testCases);
}

break;
Expand Down
24 changes: 13 additions & 11 deletions TmsRunner/Services/FilterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,25 @@ private string GetExternalId(MethodInfo testMethod, TestCase testCase)
return (testMethod.DeclaringType!.FullName + "." + testMethod.Name).ComputeHash();
}

public static List<TestCase> FilterTestCasesByLabels(AdapterConfig config, IReadOnlyCollection<TestCase> testCases)
public List<TestCase> FilterTestCasesByLabels(AdapterConfig config, IReadOnlyCollection<TestCase> testCases)
{
var labelsToRun = config.TmsLabelsOfTestsToRun?.Split(',').Select(x => x.Trim()).ToList();
var testCasesName = testCases.Select(t => t.FullyQualifiedName);
var testCasesToRun = new List<TestCase>();
var assembly = Assembly.LoadFrom(config.TestAssemblyPath ?? string.Empty);
var testMethods = new List<MethodInfo>(
assembly.GetExportedTypes()
.SelectMany(type => type.GetMethods())
.Where(m => testCasesName.Contains(m.DeclaringType!.FullName + "." + m.Name))
);
var allTestMethods = new List<MethodInfo>(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)
Expand All @@ -89,8 +93,6 @@ public static List<TestCase> 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);
Expand Down
2 changes: 1 addition & 1 deletion TmsRunner/TmsRunner.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.6.4</Version>
<Version>1.6.5</Version>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
5 changes: 3 additions & 2 deletions TmsRunnerTests/Services/FilterServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ public void FilterTestCases()
public void FilterTestCasesByLabels()
{
// Arrange
var filterService = new FilterService(_logger, _replacer);
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);
var actual = filterService.FilterTestCasesByLabels(config, testcases);

// Assert
Assert.AreEqual(0, actual.Count);
Expand Down

0 comments on commit 56a71ca

Please sign in to comment.