> For the complete documentation index, see [llms.txt](https://thekarel.gitbook.io/best-practices/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://thekarel.gitbook.io/best-practices/testing/purpose/integration.md).

# Integration tests

Integration tests have the same aim as e2e tests: to verify the [use cases](/best-practices/the-big-picture/architecture/services.md) are working by executing an API (REST, GraphQL, etc.).

Aim to test on real infrastructure: tools like Docker (Docker Compose) can spin up anything quickly. Mocking 3rd party services might be OK if there is no way around it, but try to avoid mocking your services.

Integration tests spin up the public interface (HTTP/GraphQL) and other resources (databases, etc.), set the configuration just like in regular deployment.

The assertions are all related to the high-level use cases: users can log in, see products, give us their money etc. Thanks to the machine-friendly API, these tests are more robust than e2e tests, so a lot more edge cases can be verified (higher coverage).

Do not auto-generate tests based on a GraphQL schema: the schema might be unfit for business purposes but still be technically valid.

Since we inject all modules that deal with the external world to the services, it's straightforward to use in-memory implementations during testing. The drawback is that someone must write these implementations and keep them up-to-date with the "real" ones - this is potentially a lot of extra effort. All in all, the gain doesn't justify the effort, in my opinion.

Suggestion: put integration tests in the public interface project, next to the `src` folder:

```bash
graph/
  src/
  features/ # <-- here
    chopChips.feature.ts
```

## Persistence tests

I suggest to cover the [persistence modules](/best-practices/the-big-picture/architecture/services.md) with dedicated integration tests, to gain confidence in data integrity. The tests should prove that the specific implementation of the [persistence API](/best-practices/the-big-picture/architecture/persistence.md#persistenceApi) handles CRUD commands as expected. The benefit of having a single API is that the same test can run against multiple implementations (just inject the test subject).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://thekarel.gitbook.io/best-practices/testing/purpose/integration.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
