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

feat: TMS-28784: add a command to create a filter for test frameworks by test run. #65

Merged
merged 1 commit into from
Dec 13, 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
6 changes: 4 additions & 2 deletions Tms.Adapter.Core/Client/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
Teardown = ConvertFixturesToModel(container.Afters),
Title = result.Title,
Description = result.Description,
Labels = ConvertLabelsToPostModel(result.Labels)
Labels = ConvertLabelsToPostModel(result.Labels),
ExternalKey = result.ExternalKey,
};
}

Expand All @@ -42,7 +43,8 @@
Teardown = ConvertFixturesToModel(container.Afters),
Title = result.Title,
Description = result.Description,
Labels = ConvertLabelsToPostModel(result.Labels)
Labels = ConvertLabelsToPostModel(result.Labels),
ExternalKey = result.ExternalKey,
};
}

Expand All @@ -56,7 +58,7 @@
ConfigurationId = new Guid(configurationId),
Links = ConvertLinksToPostModel(result.ResultLinks),
Message = result.Message,
Traces = result.Trace,

Check warning on line 61 in Tms.Adapter.Core/Client/Converter.cs

View workflow job for this annotation

GitHub Actions / validate (./Tms.Adapter.Core)

Possible null reference assignment.

Check warning on line 61 in Tms.Adapter.Core/Client/Converter.cs

View workflow job for this annotation

GitHub Actions / validate (./Tms.Adapter.XUnit)

Possible null reference assignment.
StartedOn = DateTimeOffset.FromUnixTimeMilliseconds(container.Start).UtcDateTime,
CompletedOn = DateTimeOffset.FromUnixTimeMilliseconds(container.Stop).UtcDateTime,
Duration = result.Stop - result.Start,
Expand Down Expand Up @@ -109,8 +111,8 @@
return links.Select(l =>
new LinkPostModel(url: l.Url)
{
Title = l.Title,

Check warning on line 114 in Tms.Adapter.Core/Client/Converter.cs

View workflow job for this annotation

GitHub Actions / validate (./Tms.Adapter.Core)

Possible null reference assignment.

Check warning on line 114 in Tms.Adapter.Core/Client/Converter.cs

View workflow job for this annotation

GitHub Actions / validate (./Tms.Adapter.XUnit)

Possible null reference assignment.
Description = l.Description,

Check warning on line 115 in Tms.Adapter.Core/Client/Converter.cs

View workflow job for this annotation

GitHub Actions / validate (./Tms.Adapter.Core)

Possible null reference assignment.

Check warning on line 115 in Tms.Adapter.Core/Client/Converter.cs

View workflow job for this annotation

GitHub Actions / validate (./Tms.Adapter.XUnit)

Possible null reference assignment.
Type = l.Type != null
? (LinkType?)Enum.Parse(typeof(LinkType), l.Type.ToString())
: null
Expand All @@ -123,8 +125,8 @@
return links.Select(l =>
new LinkPutModel(url: l.Url)
{
Title = l.Title,

Check warning on line 128 in Tms.Adapter.Core/Client/Converter.cs

View workflow job for this annotation

GitHub Actions / validate (./Tms.Adapter.XUnit)

Possible null reference assignment.
Description = l.Description,

Check warning on line 129 in Tms.Adapter.Core/Client/Converter.cs

View workflow job for this annotation

GitHub Actions / validate (./Tms.Adapter.XUnit)

Possible null reference assignment.
Type = l.Type != null
? (LinkType?)Enum.Parse(typeof(LinkType), l.Type.ToString())
: null
Expand Down
2 changes: 1 addition & 1 deletion Tms.Adapter.Core/Client/ITmsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface ITmsClient
Task<bool> IsAutotestExist(string externalId);
Task CreateAutotest(TestContainer result, ClassContainer container);
Task UpdateAutotest(TestContainer result, ClassContainer container);
Task UpdateAutotest(string externalId, List<Link> links);
Task UpdateAutotest(string externalId, List<Link> links, string externalKey);
Task LinkAutoTestToWorkItems(string autotestId, IEnumerable<string> workItemIds);
Task DeleteAutoTestLinkFromWorkItem(string autotestId, string workItemId);
Task<List<WorkItemIdentifierModel>> GetWorkItemsLinkedToAutoTest(string autotestId);
Expand Down
8 changes: 7 additions & 1 deletion Tms.Adapter.Core/Client/TmsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public async Task UpdateAutotest(TestContainer result, ClassContainer container)
_logger.LogDebug("Update autotest {ExternalId} is successfully", result.ExternalId);
}

public async Task UpdateAutotest(string externalId, List<Link> links)
public async Task UpdateAutotest(string externalId, List<Link> links, string externalKey)
{
_logger.LogDebug("Updating links property for autotest {ExternalId}: {@Links}", externalId, links);

Expand Down Expand Up @@ -101,6 +101,12 @@ public async Task UpdateAutotest(string externalId, List<Link> links)
Path = nameof(AutoTestPutModel.Links),
Value = putLinks,
Op = "Add"
},
new()
{
Path = nameof(AutoTestPutModel.ExternalKey),
Value = externalKey,
Op = "Replace"
}
};

Expand Down
1 change: 1 addition & 0 deletions Tms.Adapter.Core/Models/TestContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

public class TestContainer : ExecutableItem
{
public string Id { get; set; }

Check warning on line 5 in Tms.Adapter.Core/Models/TestContainer.cs

View workflow job for this annotation

GitHub Actions / test (./Tms.Adapter.CoreTests)

Non-nullable property 'Id' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string ExternalId { get; set; }

Check warning on line 6 in Tms.Adapter.Core/Models/TestContainer.cs

View workflow job for this annotation

GitHub Actions / test (./Tms.Adapter.CoreTests)

Non-nullable property 'ExternalId' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string Title { get; set; }

Check warning on line 7 in Tms.Adapter.Core/Models/TestContainer.cs

View workflow job for this annotation

GitHub Actions / test (./Tms.Adapter.CoreTests)

Non-nullable property 'Title' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public List<string> WorkItemIds { get; set; } = new ();
public string ClassName { get; set; }
public string Namespace { get; set; }
Expand All @@ -13,4 +13,5 @@
public List<Link> ResultLinks { get; set; } = new ();
public string Message { get; set; }
public string? Trace { get; set; }
public string ExternalKey { get; set; }
}
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.7.0</Version>
<Version>1.7.1</Version>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
Expand Down
5 changes: 1 addition & 4 deletions Tms.Adapter.Core/Writer/Writer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ public async Task Write(TestContainer result, ClassContainer container)
}
else
{
if (result.Links.Count != 0)
{
await _client.UpdateAutotest(result.ExternalId, result.Links);
}
await _client.UpdateAutotest(result.ExternalId, result.Links, result.ExternalKey);
}
}
else
Expand Down
18 changes: 18 additions & 0 deletions Tms.Adapter.SpecFlowPlugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,24 @@ Just run the command:
dotnet test
```

### Run with filter
To create filter by autotests you can use the Test IT CLI (use adapterMode 1 for run with filter):

```
$ export TMS_TOKEN=<YOUR_TOKEN>
$ testit autotests_filter
--url https://tms.testit.software \
--configuration-id 5236eb3f-7c05-46f9-a609-dc0278896464 \
--testrun-id 6d4ac4b7-dd67-4805-b879-18da0b89d4a8 \
--framework specflow \
--output tmp/filter.txt

$ export TMS_TEST_RUN_ID=6d4ac4b7-dd67-4805-b879-18da0b89d4a8
$ export TMS_ADAPTER_MODE=1

$ dotnet test --filter "$(cat tmp/filter.txt)"
```

### Attributes

Use attributes to specify information about autotest.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.7.0</Version>
<Version>1.7.1</Version>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
Expand Down
14 changes: 13 additions & 1 deletion Tms.Adapter.SpecFlowPlugin/TmsHelper.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Newtonsoft.Json.Linq;
using System.Collections.Specialized;
using System.Globalization;
using TechTalk.SpecFlow;
Expand Down Expand Up @@ -56,10 +57,12 @@ internal static TestContainer StartTestCase(string containerId, FeatureContext f
var scenarioInfo = scenarioContext?.ScenarioInfo ?? EmptyScenarioInfo;

var parameters = GetParameters(scenarioInfo);
var externalKey = GetExternalKey(scenarioInfo);
var testResult = new TestContainer
{
Id = Hash.NewId(),
Parameters = parameters
Parameters = parameters,
ExternalKey = externalKey,
};
testResult = TmsTagParser.AddTags(testResult, featureInfo, scenarioInfo, parameters);

Expand All @@ -82,6 +85,15 @@ private static Dictionary<string, string> GetParameters(ScenarioInfo scenarioInf
return parameters;
}

private static string GetExternalKey(ScenarioInfo scenarioInfo)
{
var textInfo = CultureInfo.CurrentCulture.TextInfo;

return textInfo
.ToTitleCase(scenarioInfo.Title)
.Replace(" ", "");
}

internal static TestContainer GetCurrentTestCase(ScenarioContext context)
{
context.TryGetValue(out TestContainer testContainer);
Expand Down
18 changes: 18 additions & 0 deletions Tms.Adapter.XUnit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@ $ testit \
--testrun-id $(cat tmp/output.txt)
```

### Run with filter
To create filter by autotests you can use the Test IT CLI (use adapterMode 1 for run with filter):

```
$ export TMS_TOKEN=<YOUR_TOKEN>
$ testit autotests_filter
--url https://tms.testit.software \
--configuration-id 5236eb3f-7c05-46f9-a609-dc0278896464 \
--testrun-id 6d4ac4b7-dd67-4805-b879-18da0b89d4a8 \
--framework xunit \
--output tmp/filter.txt

$ export TMS_TEST_RUN_ID=6d4ac4b7-dd67-4805-b879-18da0b89d4a8
$ export TMS_ADAPTER_MODE=1

$ dotnet test --filter "$(cat tmp/filter.txt)"
```

### Attributes

Use attributes to specify information about autotest.
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.7.0</Version>
<Version>1.7.1</Version>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
Expand Down
10 changes: 7 additions & 3 deletions Tms.Adapter.XUnit/TmsXunitHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,22 @@ public static void StartTestCase(ITestCaseMessage testCaseMessage)
}

var testCase = testCaseMessage.TestCase;
var nameSpace = GetNameSpace(testCase.TestMethod.TestClass.Class.Name);
var className = GetClassName(testCase.TestMethod.TestClass.Class.Name);
var externalKey = testCase.DisplayName;
testResults.TestResult = new TestContainer
{
Id = Hash.NewId(),
ClassName = GetClassName(testCase.TestMethod.TestClass.Class.Name),
Namespace = GetNameSpace(testCase.TestMethod.TestClass.Class.Name),
ClassName = className,
Namespace = nameSpace,
Parameters = testCase.TestMethod.Method.GetParameters()
.Zip(testCase.TestMethodArguments ?? Array.Empty<object>(), (parameter, value) => new
{
parameter,
value
})
.ToDictionary(x => x.parameter.Name, x => x.value.ToString())
.ToDictionary(x => x.parameter.Name, x => x.value.ToString()),
ExternalKey = externalKey,
};
UpdateTestDataFromAttributes(testResults.TestResult, testCase);
AdapterManager.Instance.StartTestCase(testResults.ClassContainer.Id, testResults.TestResult);
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.7.0</Version>
<Version>1.7.1</Version>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
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.7.0</Version>
<Version>1.7.1</Version>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
Loading