https://github.com/jkone27/fsharp-integration-tests
DSL wrapper around .NET test WebApplicationFactory to simplify integration tests in aspnetcore using F#
https://github.com/jkone27/fsharp-integration-tests
api-client aspnetcore dotnet fsharp http integration integration-test mock stub test
Last synced: 24 days ago
JSON representation
DSL wrapper around .NET test WebApplicationFactory to simplify integration tests in aspnetcore using F#
- Host: GitHub
- URL: https://github.com/jkone27/fsharp-integration-tests
- Owner: jkone27
- License: mit
- Created: 2022-04-05T20:14:38.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2025-02-27T21:11:19.000Z (2 months ago)
- Last Synced: 2025-03-26T23:36:39.117Z (about 1 month ago)
- Topics: api-client, aspnetcore, dotnet, fsharp, http, integration, integration-test, mock, stub, test
- Language: F#
- Homepage: https://jkone27.github.io/fsharp-integration-tests/
- Size: 349 KB
- Stars: 40
- Watchers: 4
- Forks: 1
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ApiStub.FSharp [](https://www.nuget.org/packages/ApiStub.FSharp) 🦔

![]()
[](https://stand-with-ukraine.pp.ua)
[](https://techforpalestine.org/learn-more)## Easy API Testing 🧞♀️
This library makes use of [F# computation expressions](https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/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](https://jkone27.github.io/fsharp-integration-tests/) for more info on how to use this library.
## Scenario
```mermaid
sequenceDiagram
participant TestClient as Test
participant MainApp as App
participant DependencyApp as DepTestClient->>MainApp: GET /Hello
MainApp->>DependencyApp: GET /externalApi
DependencyApp-->>MainApp: Response
MainApp-->>TestClient: Response```
## Test
```fsharp
open ApiStub.FSharp.CE
open ApiStub.FSharp.BuilderExtensions
open ApiStub.FSharp.HttpResponseHelpers
open Xunitmodule Tests =
// build your aspnetcore integration testing CE
let test = new TestClient()[]
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](https://learn.microsoft.com/bs-latn-ba/dotnet/core/tools/dotnet-add-reference).
## 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
* more info on [F# xunit testing](https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-fsharp-with-dotnet-test).
* more general info on aspnetcore integration testing if you use [Nunit](https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-fsharp-with-nunit) instead.
* [aspnetcore integration testing](https://learn.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-7.0) docs in C#