You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Testing is essential for building reliable GraphQL servers. But not every test gives you the same kind of feedback, and not every test belongs at every stage of development. This guide explains the differences between unit tests, integration tests, and end-to-end (E2E) tests, so you can choose the right approach for your project.
8
+
Testing is essential for building reliable GraphQL servers. But not every test
9
+
gives you the same kind of feedback, and not every test belongs at every stage of development.
10
+
This guide explains the differences between unit tests, integration tests, and
11
+
end-to-end (E2E) tests, so you can choose the right approach for your project.
9
12
10
13
## Unit tests
11
14
12
-
Unit tests focus on testing resolver functions in isolation. You run the resolver directly with mocked arguments and context. These tests do not involve your schema or run actual GraphQL queries.
15
+
Unit tests focus on testing resolver functions in isolation. You run the resolver directly
16
+
with mocked arguments and context. These tests do not involve your schema or run actual
17
+
GraphQL queries.
13
18
14
19
When you write unit tests, you’re checking that the resolver:
20
+
15
21
- Receives input arguments and context as expected
16
22
- Calls the correct business logic
17
23
- Handles errors properly
18
24
- Returns the correct result
19
25
20
26
Unit tests are fast and provide tight feedback loops. They're especially useful when:
27
+
21
28
- Developing new resolvers
22
29
- Validating error handling and edge cases
23
30
- Refactoring resolver logic and needing immediate verification
24
31
25
-
However, unit tests have limitations. Because you're mocking inputs and skipping the schema entirely, you won’t catch issues with how your schema connects to your resolver functions. There's also a risk of false positives if your mocks drift from real usage over time.
32
+
However, unit tests have limitations. Because you're mocking inputs and skipping the schema
33
+
entirely, you won’t catch issues with how your schema connects to your resolver functions.
34
+
There's also a risk of false positives if your mocks drift from real usage over time.
26
35
27
36
### Example: Unit test for a resolver
28
37
29
-
This test verifies that the resolver produces the expected result, using mocked inputs.
38
+
This test verifies that the resolver produces the expected result using mocked inputs.
0 commit comments