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

Folders and files

NameName
Last commit message
Last commit date

Latest commit

7082d89 Β· Feb 27, 2025
Feb 13, 2025
Feb 18, 2025
Feb 9, 2025
Feb 9, 2025
Feb 13, 2025
Feb 27, 2025
Feb 23, 2025
Feb 9, 2025
Feb 13, 2025
Feb 9, 2025
Feb 13, 2025
Jun 18, 2023
Feb 17, 2025
Jul 9, 2023
Feb 27, 2025

Repository files navigation

ApiStub.FSharp NuGet Badge πŸ¦”

alt text

JUST_STOP_OIL
Stand With Ukraine
Ceasefire Now

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.

An "antique" C# API (πŸ‘΄πŸ½πŸ¦–πŸ¦•) is also available since v.1.1 for enhanced accessibility 😺.

Documentation

Access the documentation website for more info on how to use this library.

Scenario

Loading
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

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