Skip to content

Commit e3cfe46

Browse files
committed
Another big refactoring, added tests, and now uses subresults to group results under their fixture
1 parent 29c6cf9 commit e3cfe46

15 files changed

Lines changed: 585 additions & 135 deletions

AzurePipelines.TestLogger.sln

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{C95ECC05-F3E
66
EndProject
77
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AzurePipelines.TestLogger", "src\AzurePipelines.TestLogger\AzurePipelines.TestLogger.csproj", "{77CA5040-B4A0-4D0B-ADDD-09853A385007}"
88
EndProject
9+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{FA92AD98-1291-4A90-A3AA-ED81A9BBC86E}"
10+
EndProject
11+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzurePipelines.TestLogger.Tests", "tests\AzurePipelines.TestLogger.Tests\AzurePipelines.TestLogger.Tests.csproj", "{8C42EBD4-FF36-44B6-A70E-7D83CB0626F8}"
12+
EndProject
913
Global
1014
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1115
Debug|Any CPU = Debug|Any CPU
@@ -28,12 +32,25 @@ Global
2832
{77CA5040-B4A0-4D0B-ADDD-09853A385007}.Release|x64.Build.0 = Release|Any CPU
2933
{77CA5040-B4A0-4D0B-ADDD-09853A385007}.Release|x86.ActiveCfg = Release|Any CPU
3034
{77CA5040-B4A0-4D0B-ADDD-09853A385007}.Release|x86.Build.0 = Release|Any CPU
35+
{8C42EBD4-FF36-44B6-A70E-7D83CB0626F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
36+
{8C42EBD4-FF36-44B6-A70E-7D83CB0626F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
37+
{8C42EBD4-FF36-44B6-A70E-7D83CB0626F8}.Debug|x64.ActiveCfg = Debug|Any CPU
38+
{8C42EBD4-FF36-44B6-A70E-7D83CB0626F8}.Debug|x64.Build.0 = Debug|Any CPU
39+
{8C42EBD4-FF36-44B6-A70E-7D83CB0626F8}.Debug|x86.ActiveCfg = Debug|Any CPU
40+
{8C42EBD4-FF36-44B6-A70E-7D83CB0626F8}.Debug|x86.Build.0 = Debug|Any CPU
41+
{8C42EBD4-FF36-44B6-A70E-7D83CB0626F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
42+
{8C42EBD4-FF36-44B6-A70E-7D83CB0626F8}.Release|Any CPU.Build.0 = Release|Any CPU
43+
{8C42EBD4-FF36-44B6-A70E-7D83CB0626F8}.Release|x64.ActiveCfg = Release|Any CPU
44+
{8C42EBD4-FF36-44B6-A70E-7D83CB0626F8}.Release|x64.Build.0 = Release|Any CPU
45+
{8C42EBD4-FF36-44B6-A70E-7D83CB0626F8}.Release|x86.ActiveCfg = Release|Any CPU
46+
{8C42EBD4-FF36-44B6-A70E-7D83CB0626F8}.Release|x86.Build.0 = Release|Any CPU
3147
EndGlobalSection
3248
GlobalSection(SolutionProperties) = preSolution
3349
HideSolutionNode = FALSE
3450
EndGlobalSection
3551
GlobalSection(NestedProjects) = preSolution
3652
{77CA5040-B4A0-4D0B-ADDD-09853A385007} = {C95ECC05-F3E8-49F4-B7C5-A29CD7EACFC1}
53+
{8C42EBD4-FF36-44B6-A70E-7D83CB0626F8} = {FA92AD98-1291-4A90-A3AA-ED81A9BBC86E}
3754
EndGlobalSection
3855
GlobalSection(ExtensibilityGlobals) = postSolution
3956
SolutionGuid = {A7517899-6171-4E6B-BDD7-DBE01B34E83A}

ReleaseNotes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.4.0
2+
3+
- [Feature] Now groups tests under their fixture
4+
15
# 0.3.0
26

37
- [Refactoring] Renamed to AzurePipelines.TestLogger

src/AzurePipelines.TestLogger/ApiClient.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace AzurePipelines.TestLogger
1111
{
12-
internal class ApiClient
12+
internal class ApiClient : IApiClient
1313
{
1414
private static readonly HttpClient _client = new HttpClient();
1515

@@ -26,9 +26,22 @@ public ApiClient(string accessToken, string collectionUri, string teamProject)
2626

2727
public async Task<string> SendAsync(HttpMethod method, string endpoint, string apiVersion, string body, CancellationToken cancellationToken)
2828
{
29+
if (method == null)
30+
{
31+
throw new ArgumentNullException(nameof(method));
32+
}
33+
34+
if (apiVersion == null)
35+
{
36+
throw new ArgumentNullException(nameof(apiVersion));
37+
}
38+
2939
string requestUri = $"{ _baseUrl }{ endpoint }?api-version={ apiVersion }";
3040
HttpRequestMessage request = new HttpRequestMessage(method, requestUri);
31-
request.Content = new StringContent(body, Encoding.UTF8, "application/json");
41+
if (body != null)
42+
{
43+
request.Content = new StringContent(body, Encoding.UTF8, "application/json");
44+
}
3245
HttpResponseMessage response = await _client.SendAsync(request, cancellationToken);
3346
try
3447
{

src/AzurePipelines.TestLogger/AzurePipelines.TestLogger.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,10 @@
99
<ItemGroup>
1010
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="15.0.0" />
1111
</ItemGroup>
12+
13+
<ItemGroup>
14+
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
15+
<_Parameter1>AzurePipelines.TestLogger.Tests</_Parameter1>
16+
</AssemblyAttribute>
17+
</ItemGroup>
1218
</Project>

src/AzurePipelines.TestLogger/AzurePipelinesTestLogger.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,19 @@ public class AzurePipelinesTestLogger : ITestLogger
2424
/// </summary>
2525
public const string FriendlyName = "AzurePipelines";
2626

27+
private IApiClient _apiClient;
2728
private LoggerQueue _queue;
2829

30+
public AzurePipelinesTestLogger()
31+
{
32+
}
33+
34+
// Used for testing
35+
internal AzurePipelinesTestLogger(IApiClient apiClient)
36+
{
37+
_apiClient = apiClient;
38+
}
39+
2940
public void Initialize(TestLoggerEvents events, string testRunDirectory)
3041
{
3142
if(!GetRequiredVariable("SYSTEM_ACCESSTOKEN", out string accessToken)
@@ -38,8 +49,11 @@ public void Initialize(TestLoggerEvents events, string testRunDirectory)
3849
return;
3950
}
4051

41-
ApiClient apiClient = new ApiClient(accessToken, collectionUri, teamProject);
42-
_queue = new LoggerQueue(apiClient, buildId, agentName, jobName);
52+
if (_apiClient == null)
53+
{
54+
_apiClient = new ApiClient(accessToken, collectionUri, teamProject);
55+
}
56+
_queue = new LoggerQueue(_apiClient, buildId, agentName, jobName);
4357

4458
// Register for the events
4559
events.TestRunMessage += TestMessageHandler;
@@ -63,7 +77,8 @@ private void TestMessageHandler(object sender, TestRunMessageEventArgs e)
6377
// Add code to handle message
6478
}
6579

66-
private void TestResultHandler(object sender, TestResultEventArgs e) => _queue.Enqueue(e.Result);
80+
private void TestResultHandler(object sender, TestResultEventArgs e) =>
81+
_queue.Enqueue(new VstpTestResult(e.Result));
6782

6883
private void TestRunCompleteHandler(object sender, TestRunCompleteEventArgs e) => _queue.Flush();
6984
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Net.Http;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
5+
namespace AzurePipelines.TestLogger
6+
{
7+
internal interface IApiClient
8+
{
9+
Task<string> SendAsync(HttpMethod method, string endpoint, string apiVersion, string body, CancellationToken cancellationToken);
10+
}
11+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Collections.ObjectModel;
5+
using System.Text;
6+
7+
namespace AzurePipelines.TestLogger
8+
{
9+
internal interface ITestResult
10+
{
11+
string Source { get; }
12+
string FullyQualifiedName { get; }
13+
string DisplayName { get; }
14+
TestOutcome Outcome { get; }
15+
TimeSpan Duration { get; }
16+
string ErrorStackTrace { get; }
17+
string ErrorMessage { get; }
18+
IList<TestResultMessage> Messages { get; }
19+
}
20+
}

0 commit comments

Comments
 (0)