Keploy logo
.NET logo

Keploy as a .NET testing framework

Keploy tests .NET services by recording real HTTP and EF Core traffic from a running application, then replaying it as assertions. There are no Moq setups to write, no interface per service to inject, and no in-memory provider standing in for your real database.

Generate .NET tests free
keploy record -c "dotnet Orders.dll"
18.4K+VS Code1.2M+300M+mocks created

What Keploy gives a .NET team

Any .NET service, unchanged

Keploy runs the assembly you publish. ASP.NET Core MVC, Minimal APIs, gRPC services, and Worker Services all record the same way, because capture happens at the socket rather than inside the middleware pipeline.

  • .NET 6 and above
  • Minimal APIs and MVC controllers
  • Kestrel or IIS hosting
  • No WebApplicationFactory needed
The problem

Why .NET integration tests slow teams down

The friction is rarely the assertions. It is everything around them — spinning up dependencies, keeping mocks honest, and repairing tests after every refactor.

Three ways to do it

Testing .NET: by hand, with xUnit + Moq, or with Keploy

Moq setups and an in-memory provider are both stand-ins written from your model of a dependency. Keploy records what the dependency actually returned, so a mock cannot quietly diverge from it.

Select any row for the full comparison, with code.

Same coverage, three costs

What you write for .NET vs what Keploy records

All three produce the same assertion. Only the third still passes after the next refactor without anyone editing it.

By hand2–4 hours
OrderControllerTests.cs
hand-written
// Hand-written: interfaces and fakes exist only for this test.
using Xunit;
 
public class FakeOrderRepository : IOrderRepository
{
public Task<Order> GetAsync(string id) =>
Task.FromResult(new Order(id, 4200, "NEW"));
}
 
public class FakePayments : IPaymentClient
{
public Task<string> AuthorizeAsync(string token) =>
Task.FromResult("AUTHORIZED");
}
 
public class OrderControllerTests
{
[Fact]
public async Task ConfirmsAnAuthorizedOrder()
{
var controller = new OrderController(
new FakeOrderRepository(), new FakePayments());
 
var result = await controller.Confirm("ord_1", "tok_123");
 
Assert.Equal("CONFIRMED", result.Value.State);
}
}

Two interfaces exist in production code purely so these fakes can be injected. Neither fake fails when the real Stripe or SQL contract changes.

xUnit + Moq1–2 hours
OrderControllerMoqTests.cs
tool-assisted
// xUnit + Moq + the EF Core in-memory provider.
using Microsoft.EntityFrameworkCore;
using Moq;
using Xunit;
 
public class OrderControllerMoqTests
{
[Fact]
public async Task ConfirmsAnAuthorizedOrder()
{
var options = new DbContextOptionsBuilder<OrdersDb>()
.UseInMemoryDatabase("orders-test")
.Options;
 
await using var db = new OrdersDb(options);
db.Orders.Add(new Order("ord_1", 4200, "NEW"));
await db.SaveChangesAsync();
 
// A literal that will not change when Stripe does.
var payments = new Mock<IPaymentClient>();
payments.Setup(p => p.AuthorizeAsync("tok_123"))
.ReturnsAsync("AUTHORIZED");
 
var controller = new OrderController(new EfOrderRepository(db), payments.Object);
var result = await controller.Confirm("ord_1", "tok_123");
 
Assert.Equal("CONFIRMED", result.Value.State);
payments.Verify(p => p.AuthorizeAsync("tok_123"), Times.Once);
}
}

Strongly typed and fast — and the in-memory provider never translates SQL, so a query bug reaches production unseen.

With Keploy~5 minutes
test-1.yaml
auto-generated
# Recorded with: keploy record -c 'dotnet Orders.dll'
# No Moq setup, no in-memory provider, no test host.
version: api.keploy.io/v1beta1
kind: Http
name: test-1
spec:
req:
method: POST
url: /orders/ord_1/confirm
body: '{"paymentToken":"tok_123"}'
resp:
status_code: 200
body:
id: "ord_1"
state: "CONFIRMED"
amountMinor: 4200
confirmedAt: "2026-09-02T11:04:18Z"
noise:
- body.confirmedAt
mocks:
- kind: SQL
operation: "SELECT [o].[Id], [o].[AmountMinor], [o].[State] FROM [Orders] AS [o] WHERE [o].[Id] = @__id_0"
- kind: Http
url: https://api.payments.example.com/v1/payment_intents/tok_123/confirm
status: 200

The mock is the SQL EF Core actually generated, parameter placeholders included — so a translation bug shows up as a diff instead of passing against an in-memory store.

Times are estimates for authoring one endpoint’s coverage from scratch, not measurements.

Keploy vs the alternatives

.NET testing tools, compared

The options a team on .NET actually reaches for, and where each one genuinely wins. Select a row for the full comparison.

Best in classStrongPartialNot covered

Assessments reflect each tool’s documented behaviour, not benchmark measurements.

How it works

Record your .NET app once, replay it forever

Keploy sits below your .NET process at the network layer. It watches the calls your app already makes, then serves them back on replay so tests run with no dependencies attached.

Keploy records a GET call to /api/v1/orders/{id} on a .NET service and captures the dependency calls it makes.

An example shape of a captured call. Your own endpoints and dependencies come from your real traffic, so nothing here has to be written by hand.
Mock coverage

What Keploy mocks for .NET, with zero config

7 of the 8 dependencies a typical .NET service talks to are stubbed from the recording itself — no mock classes, no fixture files, no containers in CI.

Quick start

Your first .NET test suite in under five minutes

Every command below runs against your existing .NET service. Nothing in your source tree changes.

  1. 1Install the Keploy CLI

    A single binary. It needs a Linux kernel with eBPF support, or Docker on macOS and Windows — and it adds nothing to your project's dependencies.

    curl -sSL https://keploy.io/install.sh | bash
  2. 2Record your service

    Pass the command you already use to start the app. Keploy runs it and watches every socket it opens.

    keploy record -c "dotnet Orders.dll"
  3. 3Exercise the paths you care about

    Publish as normal, then drive the app. Every request becomes a test case with its EF Core queries and HttpClient calls captured alongside.

    dotnet publish -c Release -o out
    curl -X POST localhost:5000/orders/ord_1/confirm -H 'Content-Type: application/json' -d '{"paymentToken":"tok_123"}'
  4. 4Replay in CI

    Replay serves the recorded dependency responses, so the job needs no service containers and no Docker daemon.

    keploy test -c "dotnet Orders.dll" --delay 12

Ready to try it on your own .NET service?

Ecosystem

Works with the rest of your .NET stack

Keploy records at the network layer, so framework and driver choices inside your .NET app do not change how it captures traffic.

FAQ

.NET testing with Keploy: common questions

Join our GlobalCommunity

Connect with developers worldwide. Follow updates, ask questions, share feedback, and ship faster with other Keploy builders.

1.2M+Installs
18.4K+GitHub
100K+Devs
300M+Mocks
1K+Contributors
#1OSS Trending
4.9★★★★★from 500+ reviews onG2GartnerVS CodeChrome
★★★★★

Best report of integration and API tests I've seen — which we don't get from RestAssured.

G2
★★★★★

Future of microservices testing. I don't write tests now!

G2 · 5/5
★★★★★

An amazing product that simplifies the automation.

Gartner · 4.0
XGitHubSlackYouTubeLinkedIn
Built by developers, for developers.Let's build the future, together.