-
-
Notifications
You must be signed in to change notification settings - Fork 445
External YAML file as reusable content
The following example shows how to reuse an external YAML file (or an external YAML step) as re-usable content in Zerocode test cases, using the new ${YAML.FILE:<path>} token.
This mirrors the already existing ${JSON.FILE:<path>} token(see: External JSON file content) but lets you author the re-usable content(or even a whole step) in YAML instead of JSON.
Raised via Issue #492 and delivered via PR #505.
Dependency:
<dependency>
<groupId>org.jsmart</groupId>
<artifactId>zerocode-tdd</artifactId>
<version>check-latest-in-readme-github</version>
</dependency>- You already have (or prefer to write) a step, a request body, or an expected response body in YAML, and want to reuse it across one or more test scenarios(JSON or YAML) instead of duplicating it.
- You are gradually moving your test suite from JSON to YAML and want both formats to interoperate - a JSON scenario can pull in a YAML step, and vice versa.
Main scenario file - scenario_get_api_step_test.yml
---
scenarioName: "GIVEN-the GitHub REST end point, WHEN-I invoke GET, THEN-I will receive the 200 status with body"
steps:
- stepFile: ${YAML.FILE:unit_test_files/yaml/scenario_get_api_step.yml}Re-usable step file - scenario_get_api_step.yml
name: "get_user_details"
url: "/users/googlebot"
operation: "GET"
request:
-
verify:
status: 200
body:
login: "googlebot"
type: "User"
verifyabove is just an alias ofassertions- both are supported, use whichever reads better for your team.
The same ${YAML.FILE:<path>} token also works for any leaf node inside a step, e.g. to pull in a re-usable request or expected-response body from a separate .yaml/.yml file - exactly the way ${JSON.FILE:<path>} already works:
{
"scenarioName": "POST API - Yaml file as request/response content - Reuse body",
"steps": [
{
"name": "create_emp",
"url": "/api/v1/employees",
"operation": "POST",
"request": {
"body" : "${YAML.FILE:reusable_content/request/request_body.yaml}"
},
"assertions": {
"status": 201
}
}
]
}where request_body.yaml:
name: "Emma"
surName: "Norton"This feature is covered by the below unit tests in the Zerocode repo itself:
- Test runner:
YamlUnitTest.java - Main scenario file:
scenario_get_api_step_test.yml - Re-usable step file:
scenario_get_api_step.yml
V 1.4.x - see the releases page for the exact version that includes PR #505.
Visit the Zerocode Documentation Site for all usages.
-
User's Guide
-
Matchers
-
Zerocode Value Tokens
-
YAML DSL
-
Http Testing
- External JSON file content
- External YAML file content / YAML step-reuse
- Env Switching - CI,DIT,SIT etc
- Sending "Content-Type": "application/x-www-form-urlencoded"
- Http max implicit delay and connection timeout
- Retry mechanism
- File Upload Testing - Send POST request via form-data
- Sending bare JSON String in the body
-
Kafka Testing
- Introduction
- Produce, consume proto message
- Produce raw message
- Consume raw message
- Produce JSON message
- Consume JSON message
- Produce and consume XML message
- Kafka - consume the latest message or n latest messages
- Produce avro message
- Consume avro message
- KSQL in action
- Produce multiple records
- Produce from file
- Produce to a partition
- Produce and consume records with headers
- Produce n assert partition ack
- Comsume and dump to file
- commitSync vs commitAsync
- Overriding config inside a test
- Chosing String or Int or Avro Serializer
- Chosing String or Int or Avro Deserializer
- Attaching timestamp during load
- Default timestamp provided by Kafka
- Consume and assert avro schema metadata
- Error handling - produce via avro schema
- Sorting Kafka records consumed
-
DB Testing
-
Kotlin Testing
-
Performance Testing - Load and Stress
- Performance Testing - via awesome JUnit runners
- Load Vs Stress generation on target application
- Run a single test or a scenario in parallel
- Run multiple test scenarios in parallel - Production load simulation
- Dynamically change the payload for every request
- Analytics - Useful report(s) or statistics
-
Parameterized Testing
-
Docker
-
More+
-
Extensions
-
JUnit5 Jupiter Test
-
Questions And Answers(FAQ)
- What is Zerocode testing?
- SSL http https connections supported?
- How to assert array size Greater-Than Lesser-Than etc?
- How to invoke POST api?
- How to assert custom headers of the response?
- How to pass custom security token into the request header?
- When to use JUnit Suite runner and when Zerocode Package runner?
- How to execute DB SQL and assert?
- How to handle Http response other than utf-8 e.g. utf-16 or utf-32 ?
- Random Number Generator Placeholders Usages and Limits
- Automation tests for Zerocode lib itself
- Picking a leaf value from the array matching JSON Path
- Array assertions made easy, incl. size and element finder
-
Read Our Blogs
- Top 16 Open Source API Testing Tools For REST & SOAP Services - joecolantonio (Lists popular tools - Globally)
- OAuth2 Test Automation - DZone 2min Read
- Zero defect APIs - Build Pipe Line - Medium 10 min Read
- Develop ZeroDefect API's with ZeroCode! - Extreme Portal ( A must read for all developers and test engineers) 10min Read
- Performance testing using JUnit and maven - Codeproject 10 min Read
- REST API or SOAP End Point Testing - Codeproject 10min Read
- DZone- MuleSoft API Testing With Zerocode Test Framework - DZone 5min Read
- Testing need not be harder or slower, it should be easier and faster - DZone 5 min Read
- Kotlin Integration Testing simplified via Zerocode - Extreme portal 10 min Read
- and More...