diff --git a/src/Agoda.Tests.Metrics.xUnit.Tests/Agoda.Tests.Metrics.xUnit.Tests.csproj b/src/Agoda.Tests.Metrics.xUnit.Tests/Agoda.Tests.Metrics.xUnit.Tests.csproj new file mode 100644 index 0000000..7123ee5 --- /dev/null +++ b/src/Agoda.Tests.Metrics.xUnit.Tests/Agoda.Tests.Metrics.xUnit.Tests.csproj @@ -0,0 +1,29 @@ + + + + net6.0 + enable + enable + + false + true + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/src/Agoda.Tests.Metrics.xUnit.Tests/TestFrameworkReference.cs b/src/Agoda.Tests.Metrics.xUnit.Tests/TestFrameworkReference.cs new file mode 100644 index 0000000..09a0c7d --- /dev/null +++ b/src/Agoda.Tests.Metrics.xUnit.Tests/TestFrameworkReference.cs @@ -0,0 +1 @@ +[assembly: Xunit.TestFramework("Agoda.Tests.Metrics.xUnit.AgodaTestFramework", "Agoda.Tests.Metrics.xUnit")] diff --git a/src/Agoda.Tests.Metrics.xUnit.Tests/TestSuite1.cs b/src/Agoda.Tests.Metrics.xUnit.Tests/TestSuite1.cs new file mode 100644 index 0000000..a2d6e86 --- /dev/null +++ b/src/Agoda.Tests.Metrics.xUnit.Tests/TestSuite1.cs @@ -0,0 +1,35 @@ +namespace Agoda.Tests.Metrics.xUnit.Tests +{ + public class TestSuite1 + { + private readonly Random _random = new Random(); + + [Fact] + public void Test1() + { + // 25% failure rate + Assert.True(_random.Next(0, 100) > 25); + } + + [Fact] + public void Test2() + { + // 25% failure rate + Assert.True(_random.Next(0, 100) > 25); + } + + [Fact] + public void Test3() + { + // 25% failure rate + Assert.True(_random.Next(0, 100) > 25); + } + + [Fact] + public void Test4() + { + // 25% failure rate + Assert.True(_random.Next(0, 100) > 25); + } + } +} \ No newline at end of file diff --git a/src/Agoda.Tests.Metrics.xUnit.Tests/TestSuite2.cs b/src/Agoda.Tests.Metrics.xUnit.Tests/TestSuite2.cs new file mode 100644 index 0000000..3deff46 --- /dev/null +++ b/src/Agoda.Tests.Metrics.xUnit.Tests/TestSuite2.cs @@ -0,0 +1,45 @@ +namespace Agoda.Tests.Metrics.xUnit.Tests +{ + public class TestSuite2 + { + private readonly Random _random = new Random(); + + [Fact] + public void Test1() + { + // 25% failure rate + Assert.True(_random.Next(0, 100) > 25); + } + + [Fact] + public void Test2() + { + // 25% failure rate + Assert.True(_random.Next(0, 100) > 25); + } + + [Fact] + public void Test3() + { + // 25% failure rate + Assert.True(_random.Next(0, 100) > 25); + } + + [Fact] + public void Test4() + { + // 25% failure rate + Assert.True(_random.Next(0, 100) > 25); + } + + [Theory] + [InlineData(100)] + [InlineData(75)] + [InlineData(50)] + [InlineData(25)] + public void Test5(int n) + { + Assert.True(n > 25); + } + } +} diff --git a/src/Agoda.Tests.Metrics.xUnit.Tests/Usings.cs b/src/Agoda.Tests.Metrics.xUnit.Tests/Usings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/src/Agoda.Tests.Metrics.xUnit.Tests/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/src/Agoda.Tests.Metrics.xUnit/Agoda.Tests.Metrics.xUnit.csproj b/src/Agoda.Tests.Metrics.xUnit/Agoda.Tests.Metrics.xUnit.csproj index 114c176..6159ffa 100644 --- a/src/Agoda.Tests.Metrics.xUnit/Agoda.Tests.Metrics.xUnit.csproj +++ b/src/Agoda.Tests.Metrics.xUnit/Agoda.Tests.Metrics.xUnit.csproj @@ -15,10 +15,4 @@ - - - Always - - - diff --git a/src/Agoda.Tests.Metrics.xUnit/AgodaExecutor.cs b/src/Agoda.Tests.Metrics.xUnit/AgodaExecutor.cs index cd99c04..62dde8c 100644 --- a/src/Agoda.Tests.Metrics.xUnit/AgodaExecutor.cs +++ b/src/Agoda.Tests.Metrics.xUnit/AgodaExecutor.cs @@ -28,6 +28,7 @@ protected override async void RunTestCases(IEnumerable testCases var assemblyRunner = new AgodaAssemblyRunner(TestAssembly, testCases, DiagnosticMessageSink, executionMessageSink, executionOptions, _builder); await assemblyRunner.RunAsync(); _builder.Publish(); + _messageSink.OnMessage(new DiagnosticMessage("Published test results")); } catch (Exception ex) { diff --git a/src/Agoda.Tests.Metrics.xUnit/TestResultsBuilder.cs b/src/Agoda.Tests.Metrics.xUnit/TestResultsBuilder.cs index c745479..6b0752f 100644 --- a/src/Agoda.Tests.Metrics.xUnit/TestResultsBuilder.cs +++ b/src/Agoda.Tests.Metrics.xUnit/TestResultsBuilder.cs @@ -28,13 +28,17 @@ public TestResultsBuilder() /// public void Publish() { - // Create the payload - var payload = new TestCasePayload( - typeof(TestResultsBuilder).Assembly.GetName().Version.ToString(), - GitContextReader.GetGitContext(), - _testResults - ); - DevFeedbackPublisher.Publish(null, payload, DevLocalDataType.NUnit); + lock (BuilderLock) + { + // Create the payload + var payload = new TestCasePayload( + typeof(TestResultsBuilder).Assembly.GetName().Version.ToString(), + GitContextReader.GetGitContext(), + _testResults + ); + // Publish it + DevFeedbackPublisher.Publish(null, payload, DevLocalDataType.NUnit); + } } /// diff --git a/src/Agoda.Tests.Metrics.xUnit/xunit.runner.json b/src/Agoda.Tests.Metrics.xUnit/xunit.runner.json deleted file mode 100644 index 6c0d1e4..0000000 --- a/src/Agoda.Tests.Metrics.xUnit/xunit.runner.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json", - "diagnosticMessages": true -} diff --git a/src/DotnetBuildMetrics.sln b/src/DotnetBuildMetrics.sln index ce80f4c..8fc0e93 100644 --- a/src/DotnetBuildMetrics.sln +++ b/src/DotnetBuildMetrics.sln @@ -17,7 +17,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Agoda.Tests.Metrics", "Agod EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Agoda.Tests.Metrics.xUnit", "Agoda.Tests.Metrics.xUnit\Agoda.Tests.Metrics.xUnit.csproj", "{449942D5-1D87-42A9-A74F-0BA5FB9FAC97}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Agoda.Tests.Metrics.Tests", "Agoda.Tests.Metrics.Tests\Agoda.Tests.Metrics.Tests.csproj", "{80645931-22CF-4A46-B965-544E7B5D7855}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Agoda.Tests.Metrics.Tests", "Agoda.Tests.Metrics.Tests\Agoda.Tests.Metrics.Tests.csproj", "{80645931-22CF-4A46-B965-544E7B5D7855}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Agoda.Tests.Metrics.xUnit.Tests", "Agoda.Tests.MEtrics.xUnit.Tests\Agoda.Tests.Metrics.xUnit.Tests.csproj", "{66B8CAFD-5EB6-4FF4-B2F5-6D9CE0A71396}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -57,6 +59,10 @@ Global {80645931-22CF-4A46-B965-544E7B5D7855}.Debug|Any CPU.Build.0 = Debug|Any CPU {80645931-22CF-4A46-B965-544E7B5D7855}.Release|Any CPU.ActiveCfg = Release|Any CPU {80645931-22CF-4A46-B965-544E7B5D7855}.Release|Any CPU.Build.0 = Release|Any CPU + {66B8CAFD-5EB6-4FF4-B2F5-6D9CE0A71396}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {66B8CAFD-5EB6-4FF4-B2F5-6D9CE0A71396}.Debug|Any CPU.Build.0 = Debug|Any CPU + {66B8CAFD-5EB6-4FF4-B2F5-6D9CE0A71396}.Release|Any CPU.ActiveCfg = Release|Any CPU + {66B8CAFD-5EB6-4FF4-B2F5-6D9CE0A71396}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE