Skip to content

DSL wrapper around .NET test WebApplicationFactory to simplify integration tests in aspnetcore using F#

License

Notifications You must be signed in to change notification settings

jkone27/fsharp-integration-tests

Repository files navigation

ApiStub.FSharp NuGet Badge 🦔

Screenshot 2024-12-16 at 13 01 33

Ceasefire Now
Stand With Ukraine
JUST_STOP_OIL

Easy API Testing 🧞‍♀️

This library makes use of F# computation expressions to hide some complexity of WebApplicationFactory and provide the user with a domain specific language (DSL) for integration tests.

A C# API is also available, access the documentation website for more info on how to use this library.

Scenario

sequenceDiagram
    participant TestClient as Test
    participant MainApp as App
    participant DependencyApp as Dep

    TestClient->>MainApp: GET /Hello
    MainApp->>DependencyApp: GET /externalApi
    DependencyApp-->>MainApp: Response
    MainApp-->>TestClient: Response

Loading

Test

open ApiStub.FSharp.CE
open ApiStub.FSharp.BuilderExtensions
open ApiStub.FSharp.HttpResponseHelpers
open Xunit

module Tests =

    // build your aspnetcore integration testing CE
    let test = new TestClient<Startup>()

    [<Fact>]
    let ``Calls Hello and returns OK`` () =

        task {

            let client = 
                test { 
                    GETJ "/externalApi" {| Ok = "yeah" |}
                }
                |> _.GetFactory()
                |> _.CreateClient()

            let! r = client.GetAsync("/Hello")

        }

Test .NET C# 🤝 from F#

F# is a great language, but it doesn't have to be scary to try it. Integration and Unit tests are a great way to introduce F# to your team if you are already using .NET or ASPNETCORE.

In fact you can add an .fsproj within a C# aspnetcore solution .sln, and just have a single F# assembly test your C# application from F#, referencing a .csproj file is easy! just use regular dotnet add reference command.

How to Contribute ✍️

  • Search for an open issue or report one, and check if a similar issue was reported first
  • feel free to get in touch, to fork and check out the repo
  • test and find use cases for this library, testing in F# is awesome!!!!

References

About

DSL wrapper around .NET test WebApplicationFactory to simplify integration tests in aspnetcore using F#

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published