-
-
Notifications
You must be signed in to change notification settings - Fork 399
Token: Random Number
- Flavors of Random Number
- Usecases of Random Numbers
- Using ${RANDOM.NUMBER}
- Using ${RANDOM.NUMBER.FIXED}
- Using ${RANDOM.NUMBER:10}
- Using ${GLOBAL.RANDOM.NUMBER}
- Conclusion
- Available since
We can use ${RANDOM.NUMBER}
or ${RANDOM.NUMBER.FIXED}
depending on our business usecases
Use case1:
${RANDOM.NUMBER}
If we want the an ID or any field or part of a field to be a random value inside a scenario, and this value is further random
if used more than once inside that scenario
Use case2:
${RANDOM.NUMBER.FIXED}
If we want an ID or any field or part of a field to be a random value inside a scenario, and this value is fixed
or same, if used more than once inside that scenario
"steps":[{
"name": "mytest",
"url": "/orders",
"operation": "POST",
"request": {
"headers": {
"Content-Type": "application/json;charset=UTF-8"
},
"body": {
"orders": [
{
"orderId": "${RANDOM.NUMBER}",
"amount": 5,
"productName": "product1"
},
{
"orderId": "${RANDOM.NUMBER}",
"amount": 10,
"productName": "product2"
}
]
}
},
"assertions": {
"status": 200
}
}]
after replacing RANDOM.NUMBER placeholders,we get the following request:
request:
{
"headers" : {
"Content-Type" : "application/json;charset=UTF-8"
},
"body" : {
"orders" : [ {
"orderId" : "6432473468588586502",
"amount" : 5,
"productName" : "product1"
}, {
"orderId" : "6249704932535842532",
"amount" : 10,
"productName" : "product2"
} ]
}
}
Every instance of RANDOM.NUMBER is unique
Sample step:
{
"name": "mytest",
"url": "/orders",
"operation": "POST",
"request": {
"headers": {
"Content-Type": "application/json;charset=UTF-8"
},
"body": {
"orders": [
{
"orderId": "${RANDOM.NUMBER.FIXED}",
"amount": 5,
"productName": "product1"
},
{
"orderId": "${RANDOM.NUMBER.FIXED}",
"amount": 10,
"productName": "product2"
}
]
}
},
"retry":{
"max": 2,
"delay": 500
},
"assertions": {
"status": 200
}
},
after RANDOM.NUMBER.FIXED
placeholder are replaced we get the following request:
request:
{
"headers" : {
"Content-Type" : "application/json;charset=UTF-8"
},
"body" : {
"orders" : [ {
"orderId" : "6598115625161692428",
"amount" : 5,
"productName" : "product1"
}, {
"orderId" : "6598115625161692428",
"amount" : 10,
"productName" : "product2"
} ]
}
}
RANDOM.NUMBER.FIXED
placeholders get the same
random number value within the step
We can limit random numbers' length. In this case random numbers length(digit count) would be 10.
In this case all the ${GLOBAL.RANDOM.NUMBER}
random numbers are replaced with a unique number for the entire test session until JVM exits.
This can be used in the scenarios or steps or the properties files where you need the randomness of the ID for the entire test suite run
e.g. for an entire CI build job run.
Available since V 1.3.31
Please visit the Hello World Example(Click this) to see the usages.
V 1.3.19
Visit the Zerocode Documentation Site for all things.
-
User's Guide
-
Matchers
-
Zerocode Value Tokens
-
YAML DSL
-
Http Testing
-
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...