|
1 | | -using NSubstitute; |
| 1 | +using FluentAssertions; |
| 2 | +using NSubstitute; |
2 | 3 | using TeaPie.Pipelines; |
| 4 | +using TeaPie.Reporting; |
| 5 | +using TeaPie.Scripts; |
| 6 | +using TeaPie.StructureExploration; |
| 7 | +using TeaPie.TestCases; |
| 8 | +using TeaPie.Testing; |
3 | 9 | using TeaPie.Tests.Pipelines; |
4 | 10 |
|
5 | 11 | namespace TeaPie.Tests; |
@@ -96,6 +102,55 @@ public async Task EnableAddingStepsDuringPipelineRun() |
96 | 102 | await pipeline.Run(context); |
97 | 103 | } |
98 | 104 |
|
| 105 | + [Fact] |
| 106 | + public async Task ExecuteScheduledTestsBeforeRegisteredTests() |
| 107 | + { |
| 108 | + var pipeline = new ApplicationPipeline(); |
| 109 | + var executionOrder = new List<string>(); |
| 110 | + |
| 111 | + var testCase = new TestCase(new InternalFile("test.http", "test.http", null!)); |
| 112 | + var testCaseContext = new TestCaseExecutionContext(testCase); |
| 113 | + |
| 114 | + var accessor = Substitute.For<ITestCaseExecutionContextAccessor>(); |
| 115 | + accessor.Context.Returns(testCaseContext); |
| 116 | + |
| 117 | + var reporter = Substitute.For<ITestResultsSummaryReporter>(); |
| 118 | + |
| 119 | + var tester = Substitute.For<ITester>(); |
| 120 | + tester.ExecuteOrSkipTest(Arg.Any<Test>(), Arg.Any<TestCase?>()) |
| 121 | + .Returns(callInfo => |
| 122 | + { |
| 123 | + var test = callInfo.Arg<Test>(); |
| 124 | + executionOrder.Add(test.Name); |
| 125 | + return Task.FromResult(test); |
| 126 | + }); |
| 127 | + |
| 128 | + var scheduler = new TestScheduler(); |
| 129 | + var scheduledTest = CreateTest("scheduled-test", testCase); |
| 130 | + scheduler.Schedule(scheduledTest); |
| 131 | + |
| 132 | + var registeredTest = CreateTest("registered-test", testCase); |
| 133 | + testCaseContext.RegisterTest(registeredTest); |
| 134 | + |
| 135 | + var executeScheduledTestsStep = new ExecuteScheduledTestsStep(scheduler, tester); |
| 136 | + var runScriptTestsStep = new RunScriptTestsStep(accessor, reporter, tester); |
| 137 | + |
| 138 | + pipeline.AddSteps(executeScheduledTestsStep); |
| 139 | + pipeline.AddSteps(runScriptTestsStep); |
| 140 | + |
| 141 | + await pipeline.Run(CreateApplicationContext(string.Empty)); |
| 142 | + |
| 143 | + executionOrder.Should().HaveCount(2); |
| 144 | + executionOrder[0].Should().Be("scheduled-test"); |
| 145 | + executionOrder[1].Should().Be("registered-test"); |
| 146 | + } |
| 147 | + |
| 148 | + private static Test CreateTest(string name, TestCase testCase) |
| 149 | + { |
| 150 | + var result = new TestResult.NotRun { TestName = name, TestCasePath = "test.http" }; |
| 151 | + return new Test(name, false, () => Task.CompletedTask, result, testCase); |
| 152 | + } |
| 153 | + |
99 | 154 | private static ApplicationContext CreateApplicationContext(string path) |
100 | 155 | => new ApplicationContextBuilder() |
101 | 156 | .WithPath(path) |
|
0 commit comments