Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed filtering by labels with "tmsLabelsOfTestsToRun" parameter. #63

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading