Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Fluent-Endurance: Fluent Endurance Automation Framework to Fluently Create Endurance Tests

0.00/5 (No votes)
2 Mar 2021 2  
This project is about a fluent endurance automation framework whose API helps you to fluently create your endurance tests defining repetitions and timeouts.
In this post, we share samples (the solution contains set of tests which simulate certain car features), walk through setting up your tests, and look at the output.

.NET Core Publish NuGet

FluentEndurance

A fluent endurance automation framework whose API helps you to fluently create your endurance tests defining repetitions and timeouts.

Samples

For the sake of providing some examples, the solution contains set of tests which simulate certain car features.

In the following snippet, the engine must start within 1200 ms and stop within 800 ms. If any of these two operations reach the timing, the execution fails. This set of operations will repeat for 50 times.

C#
[Fact]
public Task EngineShouldStartAndStop()
    => UseFeatureSetGroup().For(Times.As(50))
        .WithSet(group => group.Create()
            .WithStep(_engineFeature, (engine, ct) => engine.Start(ct), Milliseconds.As(1200))
            .WithStep(_engineFeature, (engine, ct) => engine.Stop(ct), Milliseconds.As(800)))
        .Run();

Which outputs:

Executed engine.Start(ct) taking 1007.4665 ms
Executed engine.Stop(ct) taking 60.9244 ms
Executed engine.Start(ct) taking 1002.506 ms
Executed engine.Stop(ct) taking 58.2176 ms
...

Timespans can be used in order to define how long the operations must take instead of repeating them certain times.

C#
[Fact]
public Task EngineShouldStartRevAndStopDuringTime()
    => UseFeatureSetGroup().During(Minutes.As(1))
        .WithSet(group => group.Create().During(Seconds.As(20))
            .WithStep(_engineFeature, (engine, ct) => engine.Start(ct))
            .WithStep(_engineFeature, (engine, ct) => engine.Rev3000(ct))
            .WithStep(_engineFeature, (engine, ct) => engine.Stop(ct)))
        .Run();

Another more complete sample.

C#
[Fact]
public Task CarShouldMakeItsRoutineTwice()
    => UseFeatureSetGroup().For(Times.As(2))
        .WithSet(group => group.Create().As(<span class="pl-pds">"Warm up"</span>)
            .WithStep(_engineFeature, (engine, ct) => engine.Start(ct))
            .WithStep(_engineFeature, (engine, ct) => engine.Rev3000(ct)))
        .WithSet(group => group.Create().As("Routine")
            .WithStep(_autopilotFeature, (autopilot, ct) => autopilot.UnPark(ct))
            .WithStep(_gearsFeature, (gears, ct) => gears.ChangeToNeutral(ct))
            .WithStep(_gearsFeature, (gears, ct) => gears.ChangeToDrive(ct)))
        .WithSet(group => group.Create().As("Maneuvers").For(Times.Twice)
            .WithStep(_engineFeature, (engine, ct) => engine.Accelerate100(ct))
            .WithStep(_autopilotFeature, (autopilot, ct) => autopilot.Drive(ct))
            .WithStep(_steeringFeature, (steering, ct) => steering.Left(ct))
            .WithStep(_steeringFeature, (steering, ct) => steering.Forward(ct))
            .WithStep(_steeringFeature, (steering, ct) => steering.Right(ct))
            .WithStep(_steeringFeature, (steering, ct) => steering.Forward(ct))
            .WithStep(_engineFeature, (engine, ct) => engine.Accelerate150(ct))
            .WithStep(_brakesFeature, (brakes, ct) => brakes.BrakeTo50(ct))
            .WithStep(_autopilotFeature, (autopilot, ct) => autopilot.Drive(ct))
            .WithStep(_brakesFeature, (brakes, ct) => brakes.BrakeTo0(ct)))
        .WithSet(group => group.Create().As("Park")
            .WithStep(_engineFeature, (engine, ct) => engine.Stop(ct))
            .WithStep(_autopilotFeature, (autopilot, ct) => autopilot.Park(ct)))
        .Run();

Setup Your Tests

This library depends on IMediator for triggering events in order to provide certain status about performance during the execution.

The library provides a base class BaseTest which registers the IMediator default implementation and also provides a helper method to easily start defining the tests. Nonetheless, is up to you whether to use this class or implement yours depending on your needs.

C#
protected BaseTest(Action<IConfigurationBuilder> configureApp,  
                   Action<IServiceCollection> configureServices)
{
    var hostBuilder = new HostBuilder();
    hostBuilder.ConfigureAppConfiguration(builder =>
    {
        configureApp(builder);
        _configuration = builder.Build();
    });

    hostBuilder.ConfigureServices(collection =>
    {
        collection.AddScoped<FeatureSetGroup>();
        collection.AddSingleton<IMediator>(sp => new Mediator(sp.GetService));
        configureServices(collection);
    });

    _host = hostBuilder.Build();
}

Output Status

There are two ways of collecting notifications:

  • Live notifications by subscribing to these events.
  • Reading the events each feature has triggered at the end of the test execution.

Live Notifications Using Notification Handlers

C#
public MotionTests(ITestOutputHelper output)
    : base(
        _ => { }, 
        services =>
        {
            var notificationHandler = new StatusNotificationHandler();
            notificationHandler.Write += output.WriteLine;
            services.AddSingleton<INotificationHandler
                                 <StatusNotification>>(notificationHandler);
            services.AddSingleton<INotificationHandler
                                 <PerformanceStatusNotification>>(notificationHandler);
        })
{
    // ...
}

Reading Feature Events

C#
public Task DisposeAsync()
{
    foreach (var notification in _engineFeature.Notifications)
    {
        _output.WriteLine(notification.Content);
    }

    return Task.CompletedTask;
}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here