github.com/99designs/gqlgen@v0.17.45/TESTING.md (about) 1 How to write tests for gqlgen 2 === 3 4 Testing generated code is a little tricky, heres how its currently set up. 5 6 ### Testing responses from a server 7 8 There is a server in `codegen/testserver` that is generated as part 9 of `go generate ./...`, and tests written against it. 10 11 There are also a bunch of tests in against the examples, feel free to take examples from there. 12 13 14 ### Testing the errors generated by the binary 15 16 These tests are **really** slow, because they need to run the whole codegen step. Use them very sparingly. If you can, find a way to unit test it instead. 17 18 Take a look at `codegen/testserver/input_test.go` for an example. 19 20 ### Testing introspection 21 22 Introspection is tested by diffing the output of `graphql get-schema` against an expected output. 23 24 Setting up the integration environment is a little tricky: 25 ```bash 26 cd integration 27 go generate ./... 28 go run ./server/cmd/integration/server.go 29 ``` 30 in another terminal 31 ```bash 32 cd integration 33 npm install 34 ./node_modules/.bin/graphql-codegen 35 ``` 36 37 will write the schema to `integration/schema-fetched.graphql`, compare that with `schema-expected.graphql` 38 39 CI will run this and fail the build if the two files don't match.