Skip to content

Commit c73d77d

Browse files
Stranger6667Urigo
authored andcommitted
Add Schemathesis
1 parent 9b3233f commit c73d77d

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
name: Schemathesis
3+
description: A modern API testing tool for web applications built with Open API and GraphQL specifications.
4+
url: https://github.com/schemathesis/schemathesis
5+
github: schemathesis/schemathesis
6+
---
7+
8+
Install Schemathesis via `pip`:
9+
10+
```bash
11+
pip install schemathesis
12+
```
13+
14+
Then, create a file `test_api.py` with the content below and replace the `URL` value with your own GraphQL endpoint URL:
15+
16+
```python
17+
from hypothesis import settings
18+
import schemathesis
19+
20+
URL = "https://your.app.com/graphql"
21+
schema = schemathesis.graphql.from_url(http://github.com/%3Cspan%20class=%22pl-c1%22%3EURL%3C/span%3E)
22+
23+
@schema.parametrize()
24+
@settings(deadline=None)
25+
def test_api(case):
26+
response = case.call()
27+
case.validate_response(response)
28+
```
29+
30+
Then run `pytest test_api.py`. Note that you can write your app in any programming language; the tool will communicate with it over HTTP.
31+
32+
Schemathesis will generate valid queries automatically based on the schema and will minimize failing cases.
33+
For example, running the code above against `https://bahnql.herokuapp.com/graphql` uncovers that running the `{ search(searchTerm: "") { stations { name } } }` query leads to a server error:
34+
35+
```
36+
{"errors":[{"message":"Cannot read property \'city\' of undefined","locations":[{"line":1,"column":28}],"path":["search","stations"]}],"data":null}
37+
```

0 commit comments

Comments
 (0)