|
84 | 84 | <div></div> |
85 | 85 | </div><section style="max-width: 640px; margin-left: auto; margin-right: auto;"> |
86 | 86 | <article> |
87 | | -<p>WebTau graphql. module lets you exercise and validate a GraphQL API. It provides a simplified way to access the JSON response of an end-point and provides a DSL to execute queries and mutations. Groovy package scenarios.rest import static org.testingisdocumenting.webtau.WebTauGroovyDsl.* scenario("check weather") { def query = "{ weather { temperature } }"; graphql.execute(query) { weather.temperature.shouldBe < 100 } } package com.example.tests.junit4 import org.junit.Test import org.junit.runner.RunWith import org.testingisdocumenting.webtau.junit4.WebTauRunner import static org.testingisdocumenting.webtau.WebTauDsl.graphql @RunWith(WebTauRunner.class) class GraphQLWeatherGroovyIT { @Test void checkWeather() { def query = "{ weather { temperature } }"; graphql.execute(query) { weather.temperature.shouldBe < 100 } } } json { "data": { "weather": { "temperature": 88 } } } Java package com.example.tests.junit4; import org.junit.Test; import org.junit.runner.RunWith; import org.testingisdocumenting.webtau.junit4.WebTauRunner; import static org.testingisdocumenting.webtau.WebTauDsl.*; @RunWith(WebTauRunner.class) public class GraphQLWeatherJavaIT { @Test public void checkWeather() { String query = "{ weather { temperature } }"; graphql.execute(query, (header, body) -> { body.get("data.weather.temperature").shouldBe(lessThan(100)); }); } } json { "data": { "weather": { "temperature": 88 } } } Before diving further into writing tests for your GraphQL server, please read through the HTTP testing documentation starting with the HTTP/data-node Data node page as much of the same core principles apply to GraphQL also.The main GraphQL specific features are covered in the subsequent pages: GraphQL/queries-and-mutations Queries and Mutations GraphQL/customized-graphql-urls Customized GraphQL URLs GraphQL/report Report</p> |
| 87 | +<p>WebTau graphql. module lets you exercise and validate a GraphQL API. It provides a simplified way to access the JSON response of an end-point and provides a DSL to execute queries and mutations. Groovy package scenarios.rest import static org.testingisdocumenting.webtau.WebTauGroovyDsl.* scenario("check weather") { def query = "{ weather { temperature } }"; graphql.execute(query) { weather.temperature.shouldBe < 100 } } package com.example.tests.junit4 import org.junit.Test import org.junit.runner.RunWith import org.testingisdocumenting.webtau.junit4.WebTauRunner import static org.testingisdocumenting.webtau.WebTauDsl.graphql @RunWith(WebTauRunner.class) class GraphQLWeatherGroovyIT { @Test void checkWeather() { def query = "{ weather { temperature } }"; graphql.execute(query) { weather.temperature.shouldBe < 100 } } } Java package com.example.tests.junit4; import org.junit.Test; import org.junit.runner.RunWith; import org.testingisdocumenting.webtau.junit4.WebTauRunner; import static org.testingisdocumenting.webtau.WebTauDsl.*; @RunWith(WebTauRunner.class) public class GraphQLWeatherJavaIT { @Test public void checkWeather() { String query = "{ weather { temperature } }"; graphql.execute(query, (header, body) -> { body.get("data.weather.temperature").shouldBe(lessThan(100)); }); } } Before diving further into writing tests for your GraphQL server, please read through the HTTP testing documentation starting with the HTTP/data-node Data node page as much of the same core principles apply to GraphQL also.The main GraphQL specific features are covered in the subsequent pages: GraphQL/queries-and-mutations Queries and Mutations GraphQL/customized-graphql-urls Customized GraphQL URLs GraphQL/report Report</p> |
88 | 88 | </article> |
89 | 89 | </section> |
90 | 90 | </div> |
91 | 91 | <script type="text/javascript" src="/webtau/footer.js"></script> |
92 | 92 | <script type="text/javascript" src="/webtau/toc.js"></script> |
93 | | -<script type="text/javascript" src="/webtau/global-anchors.js"></script> |
94 | 93 | <script type="text/javascript" src="/webtau/documentation-references.js"></script> |
95 | 94 | <script type="text/javascript" src="/webtau/assets.js"></script> |
96 | 95 | <script type="text/javascript" src="/webtau/static/main.js"></script> |
|
137 | 136 | "content" : [ { |
138 | 137 | "columns" : [ { |
139 | 138 | "content" : [ { |
| 139 | + "lang" : "groovy", |
140 | 140 | "snippet" : "package scenarios.rest\n\nimport static org.testingisdocumenting.webtau.WebTauGroovyDsl.*\n\nscenario(\"check weather\") {\n def query = \"{ weather { temperature } }\";\n graphql.execute(query) {\n weather.temperature.shouldBe < 100\n }\n}", |
141 | | - "type" : "Snippet", |
142 | 141 | "title" : "GraphQL API test (Groovy specific runner)", |
143 | | - "lang" : "groovy" |
| 142 | + "type" : "Snippet" |
144 | 143 | }, { |
| 144 | + "lang" : "groovy", |
145 | 145 | "snippet" : "package com.example.tests.junit4\n\nimport org.junit.Test\nimport org.junit.runner.RunWith\nimport org.testingisdocumenting.webtau.junit4.WebTauRunner\n\nimport static org.testingisdocumenting.webtau.WebTauDsl.graphql\n\n@RunWith(WebTauRunner.class)\nclass GraphQLWeatherGroovyIT {\n @Test\n void checkWeather() {\n def query = \"{ weather { temperature } }\";\n graphql.execute(query) {\n weather.temperature.shouldBe < 100\n }\n }\n}", |
146 | | - "type" : "Snippet", |
147 | 146 | "title" : "GraphQL API test (JUnit4)", |
148 | | - "lang" : "groovy" |
| 147 | + "type" : "Snippet" |
149 | 148 | } ] |
150 | 149 | }, { |
151 | 150 | "content" : [ { |
152 | | - "snippet" : "{\n \"data\": {\n \"weather\": {\n \"temperature\": 88\n }\n }\n}\n", |
153 | | - "type" : "Snippet", |
154 | 151 | "title" : "Server Response", |
155 | | - "lineNumber" : "", |
156 | | - "lang" : "json" |
| 152 | + "data" : { |
| 153 | + "data" : { |
| 154 | + "weather" : { |
| 155 | + "temperature" : 88 |
| 156 | + } |
| 157 | + } |
| 158 | + }, |
| 159 | + "paths" : [ ], |
| 160 | + "type" : "Json" |
157 | 161 | } ] |
158 | 162 | } ], |
159 | | - "type" : "Columns", |
160 | | - "config" : { } |
| 163 | + "config" : { }, |
| 164 | + "type" : "Columns" |
161 | 165 | } ] |
162 | 166 | }, { |
163 | 167 | "name" : "Java", |
164 | 168 | "content" : [ { |
165 | 169 | "columns" : [ { |
166 | 170 | "content" : [ { |
| 171 | + "lang" : "java", |
167 | 172 | "snippet" : "package com.example.tests.junit4;\n\nimport org.junit.Test;\nimport org.junit.runner.RunWith;\nimport org.testingisdocumenting.webtau.junit4.WebTauRunner;\n\nimport static org.testingisdocumenting.webtau.WebTauDsl.*;\n\n@RunWith(WebTauRunner.class)\npublic class GraphQLWeatherJavaIT {\n @Test\n public void checkWeather() {\n String query = \"{ weather { temperature } }\";\n graphql.execute(query, (header, body) -> {\n body.get(\"data.weather.temperature\").shouldBe(lessThan(100));\n });\n }\n}", |
168 | | - "type" : "Snippet", |
169 | 173 | "title" : "GraphQL API test (JUnit4 Java)", |
170 | | - "lang" : "java" |
| 174 | + "type" : "Snippet" |
171 | 175 | } ] |
172 | 176 | }, { |
173 | 177 | "content" : [ { |
174 | | - "snippet" : "{\n \"data\": {\n \"weather\": {\n \"temperature\": 88\n }\n }\n}\n", |
175 | | - "type" : "Snippet", |
176 | 178 | "title" : "Server Response", |
177 | | - "lineNumber" : "", |
178 | | - "lang" : "json" |
| 179 | + "data" : { |
| 180 | + "data" : { |
| 181 | + "weather" : { |
| 182 | + "temperature" : 88 |
| 183 | + } |
| 184 | + } |
| 185 | + }, |
| 186 | + "paths" : [ ], |
| 187 | + "type" : "Json" |
179 | 188 | } ] |
180 | 189 | } ], |
181 | | - "type" : "Columns", |
182 | | - "config" : { } |
| 190 | + "config" : { }, |
| 191 | + "type" : "Columns" |
183 | 192 | } ] |
184 | 193 | } ], |
185 | 194 | "type" : "Tabs" |
|
194 | 203 | "text" : "starting with the ", |
195 | 204 | "type" : "SimpleText" |
196 | 205 | }, { |
| 206 | + "url" : "/webtau/HTTP/data-node", |
197 | 207 | "isFile" : false, |
198 | 208 | "type" : "Link", |
199 | 209 | "content" : [ { |
200 | 210 | "text" : "Data node page", |
201 | 211 | "type" : "SimpleText" |
202 | | - } ], |
203 | | - "url" : "/webtau/HTTP/data-node" |
| 212 | + } ] |
204 | 213 | }, { |
205 | 214 | "text" : " as much of the same core principles apply to GraphQL also.", |
206 | 215 | "type" : "SimpleText" |
|
213 | 222 | } ] |
214 | 223 | }, { |
215 | 224 | "bulletMarker" : "*", |
216 | | - "type" : "BulletList", |
217 | 225 | "tight" : true, |
| 226 | + "type" : "BulletList", |
218 | 227 | "content" : [ { |
219 | 228 | "type" : "ListItem", |
220 | 229 | "content" : [ { |
221 | 230 | "type" : "Paragraph", |
222 | 231 | "content" : [ { |
| 232 | + "url" : "/webtau/GraphQL/queries-and-mutations", |
223 | 233 | "isFile" : false, |
224 | 234 | "type" : "Link", |
225 | 235 | "content" : [ { |
226 | 236 | "text" : "Queries and Mutations", |
227 | 237 | "type" : "SimpleText" |
228 | | - } ], |
229 | | - "url" : "/webtau/GraphQL/queries-and-mutations" |
| 238 | + } ] |
230 | 239 | } ] |
231 | 240 | } ] |
232 | 241 | }, { |
233 | 242 | "type" : "ListItem", |
234 | 243 | "content" : [ { |
235 | 244 | "type" : "Paragraph", |
236 | 245 | "content" : [ { |
| 246 | + "url" : "/webtau/GraphQL/customized-graphql-urls", |
237 | 247 | "isFile" : false, |
238 | 248 | "type" : "Link", |
239 | 249 | "content" : [ { |
240 | 250 | "text" : "Customized GraphQL URLs", |
241 | 251 | "type" : "SimpleText" |
242 | | - } ], |
243 | | - "url" : "/webtau/GraphQL/customized-graphql-urls" |
| 252 | + } ] |
244 | 253 | } ] |
245 | 254 | } ] |
246 | 255 | }, { |
247 | 256 | "type" : "ListItem", |
248 | 257 | "content" : [ { |
249 | 258 | "type" : "Paragraph", |
250 | 259 | "content" : [ { |
| 260 | + "url" : "/webtau/GraphQL/report", |
251 | 261 | "isFile" : false, |
252 | 262 | "type" : "Link", |
253 | 263 | "content" : [ { |
254 | 264 | "text" : "Report", |
255 | 265 | "type" : "SimpleText" |
256 | | - } ], |
257 | | - "url" : "/webtau/GraphQL/report" |
| 266 | + } ] |
258 | 267 | } ] |
259 | 268 | } ] |
260 | 269 | } ] |
261 | 270 | } ], |
262 | | - "lastModifiedTime" : 1658328071382, |
| 271 | + "lastModifiedTime" : 1658346107238, |
263 | 272 | "tocItem" : { |
264 | 273 | "sectionTitle" : "GraphQL", |
265 | 274 | "pageTitle" : "Introduction", |
|
0 commit comments