|
| 1 | +using Microsoft.Testing.Platform.Builder; |
| 2 | +using Microsoft.Testing.Platform.Extensions; |
| 3 | +using Microsoft.Testing.Platform.Extensions.Messages; |
| 4 | +using Microsoft.Testing.Platform.Extensions.TestHost; |
| 5 | +using Microsoft.Testing.Platform.Extensions.TestHostControllers; |
| 6 | +using System.Reflection; |
| 7 | + |
| 8 | +namespace UnitTests |
| 9 | +{ |
| 10 | + public class Injected |
| 11 | + { |
| 12 | + public static async Task Main(string[] args) |
| 13 | + { |
| 14 | + await MainAsync(args); |
| 15 | + } |
| 16 | + |
| 17 | + public static async Task MainAsync(string[] args) |
| 18 | + { |
| 19 | + Console.WriteLine("Custom stryker testrunner starting..."); |
| 20 | + |
| 21 | + var testAssembly = Assembly.GetExecutingAssembly(); |
| 22 | + |
| 23 | + Console.WriteLine("Starting testrun"); |
| 24 | + await RunTestsAsync(args, testAssembly); |
| 25 | + } |
| 26 | + |
| 27 | + private static async Task RunTestsAsync(string[] args, Assembly testAssembly) |
| 28 | + { |
| 29 | + var testApplicationBuilder = await TestApplication.CreateBuilderAsync(args); |
| 30 | + // Register the testing framework |
| 31 | + testApplicationBuilder.AddMSTest(() => new[] { testAssembly }); |
| 32 | + var factory = new CompositeExtensionFactory<StrykerExtension>(serviceProvider => new StrykerExtension()); |
| 33 | + testApplicationBuilder.TestHost.AddDataConsumer(factory); |
| 34 | + var testApplication = await testApplicationBuilder.BuildAsync(); |
| 35 | + |
| 36 | + await testApplication.RunAsync(); |
| 37 | + } |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +internal class StrykerExtension : IDataConsumer |
| 42 | +{ |
| 43 | + public StrykerExtension() |
| 44 | + { |
| 45 | + } |
| 46 | + |
| 47 | + string IExtension.Uid => "StrykerMsTestExtension"; |
| 48 | + |
| 49 | + string IExtension.Version => "1.0"; |
| 50 | + |
| 51 | + string IExtension.DisplayName => "StrykerMsTestExtension"; |
| 52 | + |
| 53 | + string IExtension.Description => "StrykerMsTestExtension"; |
| 54 | + public Type[] DataTypesConsumed => new[] { typeof(TestNodeUpdateMessage) }; |
| 55 | + |
| 56 | + public Task ConsumeAsync( |
| 57 | + IDataProducer dataProducer, |
| 58 | + IData value, |
| 59 | + CancellationToken cancellationToken) |
| 60 | + { |
| 61 | + var testNodeUpdateMessage = (TestNodeUpdateMessage)value; |
| 62 | + |
| 63 | + switch (testNodeUpdateMessage.TestNode.Properties.Single<TestNodeStateProperty>()) |
| 64 | + { |
| 65 | + case InProgressTestNodeStateProperty _: |
| 66 | + { |
| 67 | + //Console.WriteLine("InProgressTestNodeStateProperty"); |
| 68 | + Console.WriteLine("StrykerActiveMutation: " + Environment.GetEnvironmentVariable("StrykerActiveMutation")); |
| 69 | + break; |
| 70 | + } |
| 71 | + case PassedTestNodeStateProperty passed: |
| 72 | + { |
| 73 | + //Console.WriteLine("PassedTestNodeStateProperty"); |
| 74 | + //Console.WriteLine(passed.Explanation); |
| 75 | + break; |
| 76 | + } |
| 77 | + case FailedTestNodeStateProperty failedTestNodeStateProperty: |
| 78 | + { |
| 79 | + //Console.WriteLine("FailedTestNodeStateProperty"); |
| 80 | + break; |
| 81 | + } |
| 82 | + case SkippedTestNodeStateProperty _: |
| 83 | + { |
| 84 | + //Console.WriteLine("SkippedTestNodeStateProperty"); |
| 85 | + break; |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + return Task.CompletedTask; |
| 90 | + } |
| 91 | + //public Task UpdateAsync(IEnvironmentVariables environmentVariables) => throw new NotImplementedException(); |
| 92 | + public Task<ValidationResult> ValidateTestHostEnvironmentVariablesAsync(IReadOnlyEnvironmentVariables environmentVariables) => throw new NotImplementedException(); |
| 93 | + Task<bool> IExtension.IsEnabledAsync() => Task.FromResult(true); |
| 94 | + public Task BeforeRunAsync(CancellationToken cancellationToken) => throw new NotImplementedException(); |
| 95 | + public Task AfterRunAsync(int exitCode, CancellationToken cancellation) => throw new NotImplementedException(); |
| 96 | +} |
0 commit comments