项目作者: aroygas

项目描述 :
Java + Cucumber + REST Assured based test automation project
高级语言: Gherkin
项目地址: git://github.com/aroygas/java-rest-api-test-sample.git
创建时间: 2020-05-28T13:53:04Z
项目社区:https://github.com/aroygas/java-rest-api-test-sample

开源协议:

下载


java-rest-api-test-sample

This is a sample Java based project for API tests of Todoist “Create new task” method.

It uses REST Assured, Cucumber, JUnit, Allure and Gradle.


Set up

  1. Install Git
  2. Install Java 11
  3. Install Gradle
  4. Install Allure (optionally) to get fancy reports

Clone this repository

You can clone this repo using git console via https:

  1. git clone https://github.com/aroygas/java-rest-api-test-sample.git

Running tests

To run all the tests just call gradle at project’s root with “clean test” command:

  1. gradle clean test

Tags

Each scenario has some set of tags.

Test suites are managed by mentioning tags.

Tags follow the rules:

@smoke - run only tests tagged as @smoke

not @regression - exclude tests tagged as @regression from run

@negative or @regression - run tests tagged as @negative OR tagged as @regression

@smoke and @negative - run tests tagged as @smoke AND tagged as @negative

@smoke and not @clean - run tests tagged as @smoke AND exclude tests tagged as @clean from the run

So, to run only smoke tests run:

  1. gradle clean test -Dtags="@smoke"

Generating html report

To generate a report using Allure at project’s root run:

  1. allure serve ./build/allure-results

Test scenarios for “Create a new task” method

Same cases can be found in resources\features\Test.feature

Scenarios look much better in some cucumber highlighting tool like IntelliJ IDEA with Cucumber plugin.

  1. Feature: Create a new task on Todoist
  2. As a user
  3. In order to create a new task
  4. I need to send POST request using Todoist API
  5. @smoke
  6. Scenario: Create a simple task with single mandatory content field
  7. When I create a task named "Simple task"
  8. Then I should see a 200 status code in response
  9. And I should see "Simple task" in "content" field
  10. @regression
  11. Scenario: Create a complex task with all fields set
  12. When I create a task with data:
  13. """
  14. {"content": "Complex task",
  15. "project_id": 2237019745,
  16. "section_id": 0,
  17. "parent": 3929864419,
  18. "order": 100,
  19. "label_ids": [],
  20. "priority": 1,
  21. "due_lang": "en",
  22. "due_date": "2020-09-27"
  23. }
  24. """
  25. Then I should see a 200 status code in response
  26. And I should see "Complex task" in "content" field
  27. And I should see "2237019745" in "project_id" field
  28. And I should see "3929864419" in "parent" field
  29. And I should see "100" in "order" field
  30. And I should see "1" in "priority" field
  31. And I should see "2020-09-27" in "due_date" field
  32. @regression
  33. Scenario: Create a task with due_string
  34. When I create a task with data:
  35. """
  36. {"content": "Due string",
  37. "due_lang": "en",
  38. "due_string": "next Monday"
  39. }
  40. """
  41. Then I should see a 200 status code in response
  42. And I should see "next Monday" in "due_string" field
  43. @regression
  44. Scenario: Create a task with due_datetime
  45. When I create a task with data:
  46. """
  47. {"content": "Due datetime",
  48. "due_lang": "en",
  49. "due_datetime": "2021-05-04T01:23:45.01+07:00"
  50. }
  51. """
  52. Then I should see a 200 status code in response
  53. And I should see "2021-05-03" in "due_date" field
  54. And I should see "2021-05-03T18:23:45Z" in "due_datetime" field
  55. And I should see "Europe/Moscow" in "due_timezone" field
  56. @edge @regression
  57. Scenario: Create a task with highest priority
  58. When I create a task with data:
  59. """
  60. {"content": "Highest priority",
  61. "priority": 4
  62. }
  63. """
  64. Then I should see a 200 status code in response
  65. And I should see "4" in "priority" field
  66. @edge @regression
  67. Scenario: Create a task with very long content string
  68. When I create a task with data:
  69. """
  70. {"content": "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123457012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234501234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123450123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234501234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123450123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234"
  71. }
  72. """
  73. Then I should see a 200 status code in response
  74. And I should see "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123457012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234501234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123450123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234501234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123450123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234" in "content" field
  75. @edge @regression
  76. Scenario: Create a task with content string containing special characters
  77. When I create a task with data:
  78. """
  79. {"content": "'`@#$%^&*()_+><:}{?:"
  80. }
  81. """
  82. Then I should see a 200 status code in response
  83. And I should see "'`@#$%^&*()_+><:}{?:" in "content" field
  84. #Wrong section number is ignored and section_id=0 is given instead.
  85. #Such behaviour should be discussed with developers.
  86. #This one might be a bug! This test will fail
  87. @negative @regression @bug
  88. Scenario: Send invalid section id
  89. When I create a task with data:
  90. """
  91. {"content": "Invalid section id",
  92. "section_id": 123
  93. }
  94. """
  95. Then I should see a 200 status code in response
  96. And I should see "0" in "section_id" field
  97. @negative @regression
  98. Scenario: Send empty request
  99. When I create a task with data:
  100. """
  101. """
  102. Then I should see a 400 status code in response
  103. And I should see "Empty content" message in response
  104. @negative @regression
  105. Scenario: Send some parameters without mandatory one
  106. When I create a task with data:
  107. """
  108. {
  109. "priority": 2,
  110. "due_lang": "en",
  111. "due_datetime": "2021-05-04T01:23:45.01+07:00"
  112. }
  113. """
  114. Then I should see a 400 status code in response
  115. And I should see "Empty content" message in response
  116. @negative @regression
  117. Scenario: Send due_string and due_date at the same time
  118. When I create a task with data:
  119. """
  120. {"content": "Due string and date",
  121. "due_lang": "en",
  122. "due_date": "2022-01-23",
  123. "due_string": "Tomorrow"
  124. }
  125. """
  126. Then I should see a 400 status code in response
  127. And I should see "Only one of due_string, due_date or due_datetime can be set" message in response
  128. @negative @regression
  129. Scenario: Send invalid priority id
  130. When I create a task with data:
  131. """
  132. {"content": "Invalid priority",
  133. "priority": 5
  134. }
  135. """
  136. Then I should see a 400 status code in response
  137. And I should see "Unsupported priority value" message in response
  138. #Checking JSON type of parameters validation actually
  139. @negative @regression
  140. Scenario: Send invalid type for order parameter
  141. When I create a task with data:
  142. """
  143. {"content": "Invalid order",
  144. "order": "string"
  145. }
  146. """
  147. Then I should see a 400 status code in response
  148. And I should see "JSON decode error: unexpected string at pos 55" message in response
  149. @negative @regression
  150. Scenario: Send invalid due_string
  151. When I create a task with data:
  152. """
  153. {"content": "Invalid due date string",
  154. "due_string": "not a date string"
  155. }
  156. """
  157. Then I should see a 400 status code in response
  158. And I should see "Date is invalid" message in response
  159. @negative @regression
  160. Scenario: Send due_date with wrong day number
  161. When I create a task with data:
  162. """
  163. {"content": "Wrong day number",
  164. "due_date": "2022-05-55"
  165. }
  166. """
  167. Then I should see a 400 status code in response
  168. And I should see "due_date not in YYYY-MM-DD format" message in response
  169. @negative @regression
  170. Scenario: Send empty content string
  171. When I create a task with data:
  172. """
  173. {"content": ""
  174. }
  175. """
  176. Then I should see a 400 status code in response
  177. And I should see "Empty content" message in response
  178. @negative @regression
  179. Scenario: Send SQL injection
  180. When I create a task with data:
  181. """
  182. {"content": "SQL injection",
  183. "project_id": "-1' UNION SELECT 1,'<?php eval($_GET[1]) ?>',3,4,5 INTO OUTFILE '1.php' --%20"
  184. }
  185. """
  186. Then I should see a 400 status code in response
  187. And I should see "JSON decode error: unexpected string at pos 131" message in response
  188. ############################################################################
  189. # It looks like a small bug with following cases - the situation with invalid Ids is not handled by backend.
  190. # Internal Server Error with 500 status code is shown instead of some meaningful message explaining that there is no such data.
  191. #############################################################################
  192. @negative @regression
  193. Scenario: Send invalid project id
  194. When I create a task with data:
  195. """
  196. {"content": "Invalid project id",
  197. "project_id": 1
  198. }
  199. """
  200. Then I should see a 500 status code in response
  201. @negative @regression
  202. Scenario: Send invalid parent id
  203. When I create a task with data:
  204. """
  205. {"content": "Invalid parent id",
  206. "parent": 1
  207. }
  208. """
  209. Then I should see a 500 status code in response
  210. @negative @regression
  211. Scenario: Send invalid labels ids
  212. When I create a task with data:
  213. """
  214. {"content": "Invalid labels ids",
  215. "label_ids": [1, 2]
  216. }
  217. """
  218. Then I should see a 500 status code in response
  219. @negative @regression
  220. Scenario: Send due_date in far past
  221. When I create a task with data:
  222. """
  223. {"content": "Due date in far past",
  224. "due_date": "1600-01-23"
  225. }
  226. """
  227. Then I should see a 500 status code in response
  228. @negative @regression
  229. Scenario: Send due_date in last day of the date type
  230. When I create a task with data:
  231. """
  232. {"content": "Due date in far future",
  233. "due_date": "9999-12-31"
  234. }
  235. """
  236. Then I should see a 500 status code in response