Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

pact-net

> 测试质量
Open source

.NET version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verifica

930 stars0 likes0 views
WebsiteGitHub

About

.NET version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verifica

Pact Net

Fast, easy and reliable testing for your APIs and microservices.

Pact is the de-facto API contract testing tool. Replace expensive and brittle end-to-end integration tests with fast, reliable and easy to debug unit tests.

  • ⚡ Lightning fast
  • Effortless full-stack integration testing - from the front-end to the back-end
  • Supports HTTP/REST and event-driven systems
  • ️ Configurable mock server
  • Powerful matching rules prevents brittle tests
  • Integrates with Pact Broker / PactFlow for powerful CI/CD workflows
  • Supports 12+ languages

Why use Pact?

Contract testing with Pact lets you:

  • ⚡ Test locally
  • Deploy faster
  • ⬇️ Reduce the lead time for change
  • Reduce the cost of API integration testing
  • Prevent breaking changes
  • Understand your system usage
  • Document your APIs for free
  • Remove the need for complex data fixtures
  • ‍♂️ Reduce the reliance on complex test environments

Watch our series on the problems with end-to-end integrated tests, and how contract testing can help.

Documentation

Tutorial (60 minutes)

Learn everything in Pact Net in 60 minutes

Upgrade Guides

  • Upgrade guide for 3.x or lower to 4.x
  • Upgrade guide for 4.x to 5.x

Older Versions

  • release/3.x branch
  • release/4.x branch

Need Help

  • Join our community slack workspace.
  • Stack Overflow: https://stackoverflow.com/questions/tagged/pact
  • Say on Twitter @pact_up

Installation

Via Nuget

Usage

In the sections below, we provide a brief sample of the typical flow for Pact testing using HTTP interactions, written in the XUnit framework.

A more comprehensive example which uses both HTTP and message interactions, provider states, matchers and more can be found in the samples/OrdersApi folder.

Writing a Consumer test

Pact is a consumer-driven contract testing tool, which is a fancy way of saying that the API Consumer writes a test to set out its assumptions and needs of its API Provider(s). By unit testing our API client with Pact, it will produce a contract that we can share to our Provider to confirm these assumptions and prevent breaking changes.

In this example, we are going to be testing our User API client, responsible for communicating with the UserAPI over HTTP. It currently has a single method GetUser(id) that will return a User.

Pact tests have a few key properties. We'll demonstrate a common example using the 3A Arrange/Act/Assert pattern.

…

Verifying a Provider

A provider test takes one or more pact files (contracts) as input, and Pact verifies that your provider adheres to the contract. In the simplest case, you can verify a provider as per below. In SomethingApiFixture, the provider is started. In SomethingApiTests, the fixture is verified against the pact files.

…

IMPORTANT: You can't use the Microsoft.AspNetCore.Mvc.Testing library to host your API for provider tests. If your tests are using TestServer or WebApplicationFactory then these are running the API with a special in-memory test server instead of running on a real TCP socket. This means the Rust internals can't call the API and therefore all of your provider tests will fail. You must host the API on a proper TCP socket, e.g. by using the Host method shown in the sample above, so that they can be called from non-.Net code.

Messaging Pacts

For writing messaging pacts instead of requests/response pacts, see the messaging pacts guide.

Compatibility

Operating System

Due to using a shared native library instead of C# for the main Pact logic only certain OSs are supported:

OS Arch Support
Windows x86 ❌ No
Windows x64 ✔️ Yes
Linux (libc) ARM64 ✔️ Yes
Linux (libc) x64 ✔️ Yes
Linux (libc) x86 ❌ No
Linux (musl) Any ❌ No
OSX x64 ✔️ Yes
OSX ARM64 (M1/M2) ✔️ Yes

Pact Specification

Version Status Spec Compatibility Install
5.x Stable 2, 3, 4 See installation
4.x Deprecated 2, 3 See installation
3.x Deprecated 2

Roadmap

The roadmap for Pact and Pact Net is outlined on our main website.

Contributing

See CONTRIBUTING.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C#apiscontract-testingcsharpdotnet

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category测试质量
PricingOpen source

> Related tools

J
Jest
JavaScript 测试框架
P
Playwright
现代端到端测试框架
E
eslint-plugin-test-selectors
Enforces that data-test-id attributes are added to interactive DOM elements (JSX) to help with UI testing. JSX only.