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

Bellatrix Jira Zephyr Plugin #43

Merged
merged 4 commits into from
Jul 9, 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
35 changes: 35 additions & 0 deletions BellatrixTestFramework.sln
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bellatrix.Playwright", "src
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bellatrix.Playwright.GettingStarted", "templates\Bellatrix.Playwright.GettingStarted\Bellatrix.Playwright.GettingStarted.csproj", "{EACDDFC5-A313-4981-9FFB-F41639713BB1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bellatrix.Plugins.Jira.Zephyr", "src\Bellatrix.Plugins.Jira.Zephyr\Bellatrix.Plugins.Jira.Zephyr.csproj", "{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bellatrix.Playwright.Tests", "src\Bellatrix.Playwright.Tests\Bellatrix.Playwright.Tests.csproj", "{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}"
EndProject
Global
Expand Down Expand Up @@ -1168,6 +1170,38 @@ Global
{EACDDFC5-A313-4981-9FFB-F41639713BB1}.STAGE|x64.Build.0 = Debug|Any CPU
{EACDDFC5-A313-4981-9FFB-F41639713BB1}.STAGE|x86.ActiveCfg = Debug|Any CPU
{EACDDFC5-A313-4981-9FFB-F41639713BB1}.STAGE|x86.Build.0 = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.DEBUG|Any CPU.ActiveCfg = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.DEBUG|Any CPU.Build.0 = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.DEBUG|ARM.ActiveCfg = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.DEBUG|ARM.Build.0 = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.DEBUG|x64.ActiveCfg = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.DEBUG|x64.Build.0 = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.DEBUG|x86.ActiveCfg = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.DEBUG|x86.Build.0 = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.QA|Any CPU.ActiveCfg = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.QA|Any CPU.Build.0 = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.QA|ARM.ActiveCfg = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.QA|ARM.Build.0 = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.QA|x64.ActiveCfg = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.QA|x64.Build.0 = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.QA|x86.ActiveCfg = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.QA|x86.Build.0 = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.Release|Any CPU.Build.0 = Release|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.Release|ARM.ActiveCfg = Release|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.Release|ARM.Build.0 = Release|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.Release|x64.ActiveCfg = Release|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.Release|x64.Build.0 = Release|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.Release|x86.ActiveCfg = Release|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.Release|x86.Build.0 = Release|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.STAGE|Any CPU.ActiveCfg = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.STAGE|Any CPU.Build.0 = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.STAGE|ARM.ActiveCfg = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.STAGE|ARM.Build.0 = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.STAGE|x64.ActiveCfg = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.STAGE|x64.Build.0 = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.STAGE|x86.ActiveCfg = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.STAGE|x86.Build.0 = Debug|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.DEBUG|Any CPU.ActiveCfg = Debug|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.DEBUG|Any CPU.Build.0 = Debug|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.DEBUG|ARM.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -1239,6 +1273,7 @@ Global
{1AFF3507-F2C7-4240-A9D4-B166BEAC9B6F} = {E8AA67CB-09C6-4E4B-AFF1-0D5875903C34}
{08D46A7C-4BCC-4813-B20F-C7A9039621C9} = {1DF0F472-E4CA-4EFD-9459-F5B90E2E8E67}
{EACDDFC5-A313-4981-9FFB-F41639713BB1} = {74747D87-4B09-479B-B2FC-63F2CCAC4201}
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB} = {1DF0F472-E4CA-4EFD-9459-F5B90E2E8E67}
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC} = {A48D5A62-96E5-4D44-818C-18748101CCC5}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
Expand Down
8 changes: 6 additions & 2 deletions src/Bellatrix.Core/infrastructure/MSTestBaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class MSTestBaseTest
private static readonly ThreadLocal<bool> _isConfigurationExecuted = new ThreadLocal<bool>(() => { return false; });
private static ThreadLocal<Exception> _thrownException;
private PluginProvider _currentTestExecutionProvider;
private static ThreadLocal<DateTime> _startTime = new ThreadLocal<DateTime>();

public MSTestBaseTest()
{
Expand Down Expand Up @@ -84,6 +85,7 @@ public void CoreTestInit()
_currentTestExecutionProvider.PreTestInit(TestContext.TestName, testMethodMemberInfo, testClassType, new List<object>(), categories, authors, descriptions);
TestInit();
_currentTestExecutionProvider.PostTestInit(TestContext.TestName, testMethodMemberInfo, testClassType, new List<object>(), categories, authors, descriptions);
_startTime.Value = DateTime.Now;
}
catch (Exception ex)
{
Expand All @@ -107,9 +109,11 @@ public void CoreTestCleanup()

try
{
_currentTestExecutionProvider.PreTestCleanup((TestOutcome)TestContext.CurrentTestOutcome, TestContext.TestName, testMethodMemberInfo, testClassType, new List<object>(), categories, authors, descriptions, _thrownException?.Value?.Message, _thrownException?.Value?.StackTrace, _thrownException?.Value);
TimeSpan duration = DateTime.Now - _startTime.Value;

_currentTestExecutionProvider.PreTestCleanup((TestOutcome)TestContext.CurrentTestOutcome, duration.TotalMilliseconds, TestContext.TestName, testMethodMemberInfo, testClassType, new List<object>(), categories, authors, descriptions, _thrownException?.Value?.Message, _thrownException?.Value?.StackTrace, _thrownException?.Value);
TestCleanup();
_currentTestExecutionProvider.PostTestCleanup((TestOutcome)TestContext.CurrentTestOutcome, TestContext.TestName, testMethodMemberInfo, testClassType, new List<object>(), categories, authors, descriptions, _thrownException?.Value?.Message, _thrownException?.Value?.StackTrace, _thrownException?.Value);
_currentTestExecutionProvider.PostTestCleanup((TestOutcome)TestContext.CurrentTestOutcome, duration.TotalMilliseconds, TestContext.TestName, testMethodMemberInfo, testClassType, new List<object>(), categories, authors, descriptions, _thrownException?.Value?.Message, _thrownException?.Value?.StackTrace, _thrownException?.Value);
}
catch (Exception ex)
{
Expand Down
19 changes: 17 additions & 2 deletions src/Bellatrix.Core/infrastructure/NUnitBaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using NUnit.Framework;
using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal;
using static NUnit.Framework.TestContext;

namespace Bellatrix;

Expand Down Expand Up @@ -162,7 +163,7 @@ public void CoreTestCleanup()

try
{
_currentTestExecutionProvider.PreTestCleanup((TestOutcome)TestContext.Result.Outcome.Status, TestContext.Test.Name, testMethodMemberInfo, testClassType, TestContext.CurrentContext.Test.Arguments.ToList(), categories, authors, descriptions, TestContext.Result.Message, TestContext.Result.StackTrace, _thrownException?.Value);
_currentTestExecutionProvider.PreTestCleanup((TestOutcome)TestContext.Result.Outcome.Status, GetDurationOfTest(), TestContext.Test.Name, testMethodMemberInfo, testClassType, TestContext.CurrentContext.Test.Arguments.ToList(), categories, authors, descriptions, TestContext.Result.Message, TestContext.Result.StackTrace, _thrownException?.Value);
}
catch (Exception preTestCleanupException)
{
Expand All @@ -180,7 +181,7 @@ public void CoreTestCleanup()

try
{
_currentTestExecutionProvider.PostTestCleanup((TestOutcome)TestContext.Result.Outcome.Status, TestContext.Test.FullName, testMethodMemberInfo, testClassType, TestContext.CurrentContext.Test.Arguments.ToList(), categories, authors, descriptions, TestContext.Result.Message, TestContext.Result.StackTrace, _thrownException?.Value);
_currentTestExecutionProvider.PostTestCleanup((TestOutcome)TestContext.Result.Outcome.Status, GetDurationOfTest(), TestContext.Test.FullName, testMethodMemberInfo, testClassType, TestContext.CurrentContext.Test.Arguments.ToList(), categories, authors, descriptions, TestContext.Result.Message, TestContext.Result.StackTrace, _thrownException?.Value);
}
catch (Exception postCleanupException)
{
Expand Down Expand Up @@ -306,4 +307,18 @@ private Type GetCurrentExecutionTestClassType()

return testClassType;
}

private double GetDurationOfTest()
{
var fieldInfo = typeof(ResultAdapter).GetField("_result", BindingFlags.NonPublic | BindingFlags.Instance);
if (fieldInfo != null)
{
return ((TestResult)fieldInfo.GetValue(TestContext.Result)).Duration * 1000;
}
else
{
// TODO: LOG FAILURE TO RETRIEVE
return 0;
}
}
}
48 changes: 48 additions & 0 deletions src/Bellatrix.Core/plugins/PluginEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,60 @@ public PluginEventArgs(TestOutcome testOutcome,
Descriptions = descriptions;
}

public PluginEventArgs(TestOutcome testOutcome,
double duration,
string testName,
MemberInfo testMethodMemberInfo,
Type testClassType,
List<object> arguments,
string consoleOutputMessage,
string consoleOutputStackTrace,
Exception exception,
List<string> categories,
List<string> authors,
List<string> descriptions)
: this(testOutcome,
duration,
testClassType,
arguments,
consoleOutputMessage,
consoleOutputStackTrace)
{
TestMethodMemberInfo = testMethodMemberInfo;
TestName = testName;
TestFullName = $"{TestClassName}.{TestName}";
Exception = exception;
Categories = categories;
Authors = authors;
Descriptions = descriptions;
}

public PluginEventArgs(
TestOutcome testOutcome,
Type testClassType,
List<object> arguments,
string consoleOutputMessage = null,
string consoleOutputStackTrace = null)
{
TestOutcome = testOutcome;
TestClassType = testClassType;
Arguments = arguments;
TestClassName = testClassType.FullName;
ConsoleOutputMessage = consoleOutputMessage;
ConsoleOutputStackTrace = consoleOutputStackTrace;
Container = ServicesCollection.Current.FindCollection(testClassType.FullName);
}

public PluginEventArgs(
TestOutcome testOutcome,
double duration,
Type testClassType,
List<object> arguments,
string consoleOutputMessage = null,
string consoleOutputStackTrace = null)
{
TestOutcome = testOutcome;
Duration = duration;
TestClassType = testClassType;
Arguments = arguments;
TestClassName = testClassType.FullName;
Expand All @@ -75,6 +121,8 @@ public PluginEventArgs(
public List<object> Arguments { get; }

public TestOutcome TestOutcome { get; }

public double Duration { get; }

public string TestName { get; }

Expand Down
37 changes: 37 additions & 0 deletions src/Bellatrix.Core/plugins/PluginProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,39 @@ public void PostTestInit(string testName, MemberInfo testMethodMemberInfo, Type
RaiseTestEvent(PostTestInitEvent, TestOutcome.Unknown, testName, testMethodMemberInfo, testClassType, arguments, categories, authors, descriptions);
}

/// <summary>
/// Obsolete <br></br>
/// Use PreTestCleanup method with parameter duration.
/// </summary>
public void PreTestCleanup(TestOutcome testOutcome, string testName, MemberInfo testMethodMemberInfo, Type testClassType, List<object> arguments, List<string> categories, List<string> authors, List<string> descriptions, string message, string stackTrace, Exception exception)
{
RaiseTestEvent(PreTestCleanupEvent, testOutcome, testName, testMethodMemberInfo, testClassType, arguments, categories, authors, descriptions, message, stackTrace, exception);
}

public void PreTestCleanup(TestOutcome testOutcome, double duration, string testName, MemberInfo testMethodMemberInfo, Type testClassType, List<object> arguments, List<string> categories, List<string> authors, List<string> descriptions, string message, string stackTrace, Exception exception)
{
RaiseTestEvent(PreTestCleanupEvent, testOutcome, duration, testName, testMethodMemberInfo, testClassType, arguments, categories, authors, descriptions, message, stackTrace, exception);
}

public void TestCleanupFailed(Exception ex, string testName, MemberInfo testMethodMemberInfo, Type testClassType, List<object> arguments, List<string> categories, List<string> authors, List<string> descriptions)
{
RaiseTestEvent(TestCleanupFailedEvent, TestOutcome.Failed, testName, testMethodMemberInfo, testClassType, arguments, categories, authors, descriptions, ex.Message, ex.StackTrace);
}

/// <summary>
/// Obsolete <br></br>
/// Use PostTestCleanup method with parameter duration.
/// </summary>
public void PostTestCleanup(TestOutcome testOutcome, string testName, MemberInfo testMethodMemberInfo, Type testClassType, List<object> arguments, List<string> categories, List<string> authors, List<string> descriptions, string message, string stackTrace, Exception exception)
{
RaiseTestEvent(PostTestCleanupEvent, testOutcome, testName, testMethodMemberInfo, testClassType, arguments, categories, authors, descriptions, message, stackTrace, exception);
}

public void PostTestCleanup(TestOutcome testOutcome, double duration, string testName, MemberInfo testMethodMemberInfo, Type testClassType, List<object> arguments, List<string> categories, List<string> authors, List<string> descriptions, string message, string stackTrace, Exception exception)
{
RaiseTestEvent(PostTestCleanupEvent, testOutcome, duration, testName, testMethodMemberInfo, testClassType, arguments, categories, authors, descriptions, message, stackTrace, exception);
}

public void PreClassCleanup(Type testClassType)
{
RaiseClassTestEvent(PreTestsCleanupEvent, TestOutcome.Unknown, testClassType);
Expand Down Expand Up @@ -137,4 +155,23 @@ private void RaiseTestEvent(
var args = new PluginEventArgs(testOutcome, testName, testMethodMemberInfo, testClassType, arguments, message, stackTrace, exception, categories, authors, descriptions);
eventHandler?.Invoke(this, args);
}

private void RaiseTestEvent(
EventHandler<PluginEventArgs> eventHandler,
TestOutcome testOutcome,
double duration,
string testName,
MemberInfo testMethodMemberInfo,
Type testClassType,
List<object> arguments,
List<string> categories,
List<string> authors,
List<string> descriptions,
string message = null,
string stackTrace = null,
Exception exception = null)
{
var args = new PluginEventArgs(testOutcome, duration, testName, testMethodMemberInfo, testClassType, arguments, message, stackTrace, exception, categories, authors, descriptions);
eventHandler?.Invoke(this, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="RestSharp" Version="110.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Bellatrix.Core\Bellatrix.Core.csproj" />
</ItemGroup>

<ItemGroup>
<Using Include="NUnit.Framework" />
</ItemGroup>

</Project>
Loading
Loading