|
| 1 | + |
| 2 | +# FluentEndurance |
| 3 | +A fluent endurance automation framework whose API helps you to fluently create your endurance tests defining repetitions and timeouts. |
| 4 | + |
| 5 | + |
| 6 | +## Samples |
| 7 | +For the sake of providing some examples, the solution contains set of tests which simulates certain car features. |
| 8 | + |
| 9 | +In the following snippet the engine must start within 1200 ms and stop within 800 ms. If any of these two operation reach the timing the execution fails. This set of operations will repeat for 50 times. |
| 10 | + |
| 11 | +```csharp |
| 12 | +[Fact] |
| 13 | +public Task EngineShouldStartAndStop() |
| 14 | + => UseFeatureSetGroup().For(Times.As(50)) |
| 15 | + .WithSet(group => group.Create() |
| 16 | + .WithStep(_engineFeature, (engine, ct) => engine.Start(ct), Milliseconds.As(1200)) |
| 17 | + .WithStep(_engineFeature, (engine, ct) => engine.Stop(ct), Milliseconds.As(800))) |
| 18 | + .Run(); |
| 19 | +``` |
| 20 | + |
| 21 | +Which outputs: |
| 22 | +``` |
| 23 | +Executed engine.Start(ct) taking 1007.4665 ms |
| 24 | +Executed engine.Stop(ct) taking 60.9244 ms |
| 25 | +Executed engine.Start(ct) taking 1002.506 ms |
| 26 | +Executed engine.Stop(ct) taking 58.2176 ms |
| 27 | +... |
| 28 | +``` |
| 29 | + |
| 30 | +Timespans can be used in order to define how long the operations must take instead of repeating them certain times. |
| 31 | + |
| 32 | +```csharp |
| 33 | +[Fact] |
| 34 | +public Task EngineShouldStartRevAndStopDuringTime() |
| 35 | + => UseFeatureSetGroup().During(Minutes.As(1)) |
| 36 | + .WithSet(group => group.Create().During(Seconds.As(20)) |
| 37 | + .WithStep(_engineFeature, (engine, ct) => engine.Start(ct)) |
| 38 | + .WithStep(_engineFeature, (engine, ct) => engine.Rev3000(ct)) |
| 39 | + .WithStep(_engineFeature, (engine, ct) => engine.Stop(ct))) |
| 40 | + .Run(); |
| 41 | +``` |
| 42 | + |
| 43 | +Another more complete sample. |
| 44 | + |
| 45 | +```csharp |
| 46 | +[Fact] |
| 47 | +public Task CarShouldMakeItsRoutineTwice() |
| 48 | + => UseFeatureSetGroup().For(Times.As(2)) |
| 49 | + .WithSet(group => group.Create().As("Warm up") |
| 50 | + .WithStep(_engineFeature, (engine, ct) => engine.Start(ct)) |
| 51 | + .WithStep(_engineFeature, (engine, ct) => engine.Rev3000(ct))) |
| 52 | + .WithSet(group => group.Create().As("Routine") |
| 53 | + .WithStep(_autopilotFeature, (autopilot, ct) => autopilot.UnPark(ct)) |
| 54 | + .WithStep(_gearsFeature, (gears, ct) => gears.ChangeToNeutral(ct)) |
| 55 | + .WithStep(_gearsFeature, (gears, ct) => gears.ChangeToDrive(ct))) |
| 56 | + .WithSet(group => group.Create().As("Maneuvers").For(Times.Twice) |
| 57 | + .WithStep(_engineFeature, (engine, ct) => engine.Accelerate100(ct)) |
| 58 | + .WithStep(_autopilotFeature, (autopilot, ct) => autopilot.Drive(ct)) |
| 59 | + .WithStep(_steeringFeature, (steering, ct) => steering.Left(ct)) |
| 60 | + .WithStep(_steeringFeature, (steering, ct) => steering.Forward(ct)) |
| 61 | + .WithStep(_steeringFeature, (steering, ct) => steering.Right(ct)) |
| 62 | + .WithStep(_steeringFeature, (steering, ct) => steering.Forward(ct)) |
| 63 | + .WithStep(_engineFeature, (engine, ct) => engine.Accelerate150(ct)) |
| 64 | + .WithStep(_brakesFeature, (brakes, ct) => brakes.BrakeTo50(ct)) |
| 65 | + .WithStep(_autopilotFeature, (autopilot, ct) => autopilot.Drive(ct)) |
| 66 | + .WithStep(_brakesFeature, (brakes, ct) => brakes.BrakeTo0(ct))) |
| 67 | + .WithSet(group => group.Create().As("Park") |
| 68 | + .WithStep(_engineFeature, (engine, ct) => engine.Stop(ct)) |
| 69 | + .WithStep(_autopilotFeature, (autopilot, ct) => autopilot.Park(ct))) |
| 70 | + .Run(); |
| 71 | +``` |
| 72 | + |
| 73 | +## Output status |
| 74 | + |
| 75 | +There are two ways of collecting notifications: |
| 76 | +* Live notifications by subscribing to these events. |
| 77 | +* Reading the events each feature has triggered at the end of the test execution. |
| 78 | + |
| 79 | + |
| 80 | +### Live notifications using notification handlers |
| 81 | +```csharp |
| 82 | +public MotionTests(ITestOutputHelper output) |
| 83 | + : base( |
| 84 | + _ => { }, |
| 85 | + services => |
| 86 | + { |
| 87 | + var notificationHandler = new StatusNotificationHandler(); |
| 88 | + notificationHandler.Write += output.WriteLine; |
| 89 | + services.AddSingleton<INotificationHandler<StatusNotification>>(notificationHandler); |
| 90 | + services.AddSingleton<INotificationHandler<PerformanceStatusNotification>>(notificationHandler); |
| 91 | + }) |
| 92 | +{ |
| 93 | + // ... |
| 94 | +} |
| 95 | +``` |
| 96 | + |
| 97 | +### Reading feature events |
| 98 | +```csharp |
| 99 | +public Task DisposeAsync() |
| 100 | +{ |
| 101 | + foreach (var notification in _engineFeature.Notifications) |
| 102 | + { |
| 103 | + _output.WriteLine(notification.Content); |
| 104 | + } |
| 105 | + |
| 106 | + return Task.CompletedTask; |
| 107 | +} |
| 108 | +``` |
0 commit comments