F Testing Patterns

F# testing patterns with xUnit, FsUnit, Unquote, FsCheck property-based testing, integration tests, and test organization best practices.

You say
Buy it · $59 Read it before you buy $59 Written by affaan-m · unverified publisher
Context cost
2k tokensestimated from the bundle, loaded when it triggers
Bundle
1 file · 7.9 kBtext throughout, nothing executable
Licence
MITpaid listing
Last change
no release on file
Servers it uses
Noneruns standalone

What it does

F# testing patterns with xUnit, FsUnit, Unquote, FsCheck property-based testing, integration tests, and test organization best practices. Use when writing F# tests with xUnit, FsUnit, Unquote, or FsCheck.

Installed, it changes the agent in these ways.

What this skill changes about the agent is not written down here yet. The listing was collected from its source, and the description is in its own SKILL.md.

Expertise

Domain judgement the base model does not have.

securitytesting

The skill itself

This is the whole product. A skill is instructions the model reads, so there is nothing behind the listing you cannot see first — the front matter loads with every session, and the body below it loads when the skill triggers.

SKILL.md7.9 kB · 282 lines
--- name: fsharp-testing description: F# testing patterns with xUnit, FsUnit, Unquote, FsCheck property-based testing, integration tests, and test organization best practices. Use when writing F# tests with xUnit, FsUnit, Unquote, or FsCheck. metadata: origin: ECC ---
8# F# Testing Patterns
9
10Comprehensive testing patterns for F# applications using xUnit, FsUnit, Unquote, FsCheck, and modern .NET testing practices.
11
12## When to Activate
13
14- Writing new tests for F# code
15- Reviewing test quality and coverage
16- Setting up test infrastructure for F# projects
17- Debugging flaky or slow tests
18
19## Test Framework Stack
20
21| Tool | Purpose |
22|---|---|
23| **xUnit** | Test framework (standard .NET ecosystem choice) |
24| **FsUnit.xUnit** | F#-friendly assertion syntax for xUnit |
25| **Unquote** | Assertion library using F# quotations for clear failure messages |
26| **FsCheck.xUnit** | Property-based testing integrated with xUnit |
27| **NSubstitute** | Mocking .NET dependencies |
28| **Testcontainers** | Real infrastructure in integration tests |
29| **WebApplicationFactory** | ASP.NET Core integration tests |
30
31## Unit Tests with xUnit + FsUnit
32
33### Basic Test Structure
34
35```fsharp
36module OrderServiceTests
37
38open Xunit
39open FsUnit.Xunit
40
41[<Fact>]
42let `create sets status to Pending` () =
43 let order = Order.create "cust-1" [ validItem ]
44 order.Status |> should equal Pending
45
46[<Fact>]
47let `confirm changes status to Confirmed` () =
48 let order = Order.create "cust-1" [ validItem ]
49 let confirmed = Order.confirm order
50 confirmed.Status |> should be (ofCase <@ Confirmed @>)
51```
52
53### Assertions with Unquote
54
55Unquote uses F# quotations so failure messages show the full expression that failed, not just "expected X got Y".
56
57```fsharp
58module OrderValidationTests
59
60open Xunit
61open Swensen.Unquote
62
63[<Fact>]
64let `PlaceOrder returns success when request is valid` () =
65 let request = { CustomerId = "cust-123"; Items = [ validItem ] }
66 let result = OrderService.placeOrder request
67 test <@ Result.isOk result @>
68
69[<Fact>]
70let `order total sums item prices` () =
71 let items = [ { Sku = "A"; Quantity = 2; Price = 10m }
72 { Sku = "B"; Quantity = 1; Price = 5m } ]
73 let total = Order.calculateTotal items
74 test <@ total = 25m @>
75
76[<Fact>]
77let `validated email rejects empty input` () =
78 let result = ValidatedEmail.create ""
79 test <@ Result.isError result @>
80```
81
82### Async Tests
83
84```fsharp
85[<Fact>]
86let `PlaceOrder returns success when request is valid` () = task {
87 let deps = createTestDeps ()
88 let request = { CustomerId = "cust-123"; Items = [ validItem ] }
89
90 let! result = OrderService.placeOrder deps request
91
92 test <@ Result.isOk result @>
93}
94
95[<Fact>]
96let `PlaceOrder returns error when items are empty` () = task {
97 let deps = createTestDeps ()
98 let request = { CustomerId = "cust-123"; Items = [] }
99
100 let! result = OrderService.placeOrder deps request
101
102 test <@ Result.isError result @>
103}
104```
105
106### Parameterized Tests with Theory
107
108```fsharp
109[<Theory>]
110[<InlineData("")>]
111[<InlineData(" ")>]
112let `PlaceOrder rejects empty customer ID` (customerId: string) =
113 let request = { CustomerId = customerId; Items = [ validItem ] }
114 let result = OrderService.placeOrder request
115 result |> should be (ofCase <@ Error @>)
116
117[<Theory>]
118[<InlineData("", false)>]
119[<InlineData("a", false)>]
120[<InlineData("user@example.com", true)>]
121[<InlineData("user+tag@example.co.uk", true)>]
122let `IsValidEmail returns expected result` (email: string, expected: bool) =
123 test <@ EmailValidator.isValid email = expected @>
124```
125
126## Property-Based Testing with FsCheck
127
128### Using FsCheck.xUnit
129
130```fsharp
131open FsCheck
132open FsCheck.Xunit
133
134[<Property>]
135let `order total is always non-negative` (items: NonEmptyList<PositiveInt * decimal>) =
136 let orderItems =
137 items.Get
138 |> List.map (fun (qty, price) ->
139 { Sku = "SKU"; Quantity = qty.Get; Price = abs price })
140 let total = Order.calculateTotal orderItems
141 total >= 0m
142
143[<Property>]
144let `serialization roundtrips` (order: Order) =
145 let json = JsonSerializer.Serialize order
146 let deserialized = JsonSerializer.Deserialize<Order> json
147 deserialized = order
148```
149
150### Custom Generators
151
152```fsharp
153type OrderGenerators =
154 static member ValidEmail () =
155 gen {
156 let! user = Gen.elements [ "alice"; "bob"; "carol" ]
157 let! domain = Gen.elements [ "example.com"; "test.org" ]
158 return $"{user}@{domain}"
159 }
160 |> Arb.fromGen
161
162[<Property(Arbitrary = [| typeof<OrderGenerators> |])>]
163let `valid emails pass validation` (email: string) =
164 EmailValidator.isValid email
165```
166
167## Mocking Dependencies
168
169### Function Stubs (Preferred)
170
171```fsharp
172let createTestDeps () =
173 let mutable savedOrders = []
174 { FindOrder = fun id -> task { return Map.tryFind id testData }
175 SaveOrder = fun order -> task { savedOrders <- order :: savedOrders }
176 SendNotification = fun _ -> Task.CompletedTask }
177
178[<Fact>]
179let `PlaceOrder saves the confirmed order` () = task {
180 let mutable saved = []
181 let deps =
182 { createTestDeps () with
183 SaveOrder = fun order -> task { saved <- order :: saved } }
184
185 let! _ = OrderService.placeOrder deps validRequest
186
187 test <@ saved.Length = 1 @>
188}
189```
190
191### NSubstitute for .NET Interfaces
192
193```fsharp
194open NSubstitute
195
196[<Fact>]
197let `calls repository with correct ID` () = task {
198 let repo = Substitute.For<IOrderRepository>()
199 repo.FindByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
200 .Returns(Task.FromResult(Some testOrder))
201
202 let service = OrderService(repo)
203 let! _ = service.GetOrder(testOrder.Id, CancellationToken.None)
204
205 do! repo.Received(1).FindByIdAsync(testOrder.Id, Arg.Any<CancellationToken>())
206}
207```
208
209## ASP.NET Core Integration Tests
210
211```fsharp
212type OrderApiTests (factory: WebApplicationFactory<Program>) =
213 interface IClassFixture<WebApplicationFactory<Program>>
214
215 let client =
216 factory.WithWebHostBuilder(fun builder ->
217 builder.ConfigureServices(fun services ->
218 services.RemoveAll<DbContextOptions<AppDbContext>>() |> ignore
219 services.AddDbContext<AppDbContext>(fun options ->
220 options.UseInMemoryDatabase("TestDb") |> ignore) |> ignore))
221 .CreateClient()
222
223 [<Fact>]
224 member _.`GET order returns 404 when not found` () = task {
225 let! response = client.GetAsync($"/api/orders/{Guid.NewGuid()}")
226 test <@ response.StatusCode = HttpStatusCode.NotFound @>
227 }
228```
229
230## Test Organization
231
232```
233tests/
234 MyApp.Tests/
235 Unit/
236 OrderServiceTests.fs
237 PaymentServiceTests.fs
238 Integration/
239 OrderApiTests.fs
240 OrderRepositoryTests.fs
241 Properties/
242 OrderPropertyTests.fs
243 Helpers/
244 TestData.fs
245 TestDeps.fs
246```
247
248## Common Anti-Patterns
249
250| Anti-Pattern | Fix |
251|---|---|
252| Testing implementation details | Test behavior and outcomes |
253| Mutable shared test state | Fresh state per test |
254| Thread.Sleep in async tests | Use Task.Delay with timeout, or polling helpers |
255| Asserting on sprintf output | Assert on typed values and pattern matches |
256| Ignoring CancellationToken | Always pass and verify cancellation |
257| Skipping property-based tests | Use FsCheck for any function with clear invariants |
258
259## Related Skills
260
261- dotnet-patterns - Idiomatic .NET patterns, dependency injection, and architecture
262- csharp-testing - C# testing patterns (shared infrastructure like WebApplicationFactory and Testcontainers applies to F# too)
263
264## Running Tests
265
266```bash
267# Run all tests
268dotnet test
269
270# Run with coverage
271dotnet test --collect:"XPlat Code Coverage"
272
273# Run specific project
274dotnet test tests/MyApp.Tests/
275
276# Filter by test name
277dotnet test --filter "FullyQualifiedName~OrderService"
278
279# Watch mode during development
280dotnet watch test --project tests/MyApp.Tests/
281```
282
In the file
SKILL.md1,029 words
Files1
LicenceMIT
Why you can read it

Nothing in a skill executes. The client loads the text and the model follows it, so a skill can be audited the way a runbook is — by reading it.

What it costs in context

Skills are not billed by the call. They are paid for in context: every token the instructions occupy is a token your code, your diff and your conversation cannot use. Here is what this one takes and when it takes it.

≈70
always loaded
The name and description, so the model knows the skill exists and when to reach for it.
1,905
on trigger
The instruction body, read only when the skill fires.
0.99%
of a 200k window
Ten skills this size would take about 10% of the window before you open a file.
050k100k150k200k context window

2k tokens, estimated from the bundle at four bytes to the token, held for the rest of the session once it triggers. Middling. Fine to keep on in a project where you use it weekly, worth unloading in one where you never do.

Servers bill, skills cost

A server charges by the month. A skill charges once per session, in context, and then keeps charging it for as long as the session lives.

Before and after

The same question, put to the same model twice: once as it comes, and once with these instructions loaded.

No worked example has been published for this skill yet.

Adoption
Installsnone yet
Ratingno reviews yet

The procedure it runs

The procedure has not been published here. It is in the skill’s own SKILL.md, which its author has not sent to the marketplace yet.

Prose, not code

These steps are written for a model to follow, not executed by a runtime. It can still be told to skip one, and it will say so when it does.

Servers it uses

None. This skill calls no MCP servers at all.

Everything it needs is in the instructions, so it works in a project with nothing connected — the model reads the file and changes how it works with what it can already reach.

It writes no files and reaches no network. All it changes is how the model reasons and writes.

What it asks for
Writes filesno
Network accessno

Read from the allowed-tools line of this skill’s own SKILL.md. A skill grants no permissions of its own — it can only ask for tools your client already has.

What it will not do

Every skill is narrow, and the useful ones say where they stop. These are the jobs this one is the wrong tool for.

What this skill is not for has not been published here. Nothing is implied by that: it is a section the author has not filled in.

What is in the bundle

1 file, 7.9 kB on disk. A bundle is text throughout: the instructions the model reads, plus the templates it fills in.

  • SKILL.md7.9 kB
What is not in it

No dependencies and nothing executable: a skill is text the agent reads, so the bundle is 1 file you can review in full before installing. The MIT licence covers the templates and examples as well as the instructions.

Install

Installing copies the bundle into your project. Nothing runs at install time — the files sit on disk until the model reads them.

$59 once
F Testing Patterns · MIT · affaan-m
one-time
Price$59 once
LicenceMIT — the author’s, unchanged by this purchase
Paid throughStripe, once, on the card you add at the checkout
Keeps workingfor good — the files are yours once they are on disk
Updatesevery update its author ships, delivered through this account

You can read the whole bundle before paying — the SKILL.md above is the product, not a preview of it. What the money buys is the delivery: the folder packaged and handed to your machine by key, every update its author ships, and our support if it does not do what this listing says. The terms of use are MIT, set by the author and unchanged by buying it here.

Payment runs through Stripe, on a page like this one rather than a redirect. Once there is an account it joins the same mcprush invoice as everything else you run, so there is never a second card to enter.

Which clients pick it up on their own

A skill is a folder of text. A client with a skills folder reads it without being told; everywhere else the same text works, it is just handed to the model rather than found.

Claude Code.claude/skills/
Claude Desktop
ChatGPT
Cursor.cursor/skills/
VS Code.github/skills/
Codex CLI.agents/skills/
Gemini CLI.gemini/skills/
Grok.grok/skills/
Zed.agents/skills/
Windsurf.windsurf/skills/
Agent SDK.claude/skills/
HTTP / API
This release
Versionnot versioned
Publishedno release date on file
Price$59
Referenceaffaan-m/f-testing-patterns

Versions

Its author publishes no version number, so there is nothing here to pin to: what you install is the folder as it stands today. Instructions change more often than APIs do — a skill can be rewritten entirely without anything it depends on moving.

v
  • No earlier releases have been published to the marketplace.
Pinning

Nothing to pin to: this skill carries no version number of its own. What you install is what the folder holds on the day you install it.

Reviews

no reviews yet · no installs yet

Nobody has reviewed this skill yet. The rating is the mean of the reviews written here, so there is none until somebody writes the first.

Who can post

Only accounts that have had the skill installed for fourteen days, so a review is written after living with it rather than after reading it. Publishers may reply once.

Publisher
Servers0