-
-
Notifications
You must be signed in to change notification settings - Fork 399
Reading System Properties and Environment Variables in Zerocode Test Steps
We will learn here what these properties are and why/when do we need them. Then we will see how we can use them in Zerocode test scenario steps.
The Java platform uses a Properties object (subclass of Hashtable) to maintain key value pair, where both the key and the value are strings to store information about the local system and configuration. The default System Properties include basic information like current user, JRE version, file path separator, etc.
System properties can be set on the Java command line using -Dpropertyname=value
or added/modified at runtime using System.setProperty(String key, String value)
To get a system property you can use
-
System.getProperty(String key)
or System.getProperty(String key, String defaultValue).
To use System Property in a Zerocode step
{
"scenarioName": "System Property for host",
"steps": [
{
"name": "get_api_call",
"url": "${SYSTEM.PROPERTY:hostname}/test/123",
...
}
]
}
Replaces with the value of the system property. E.g. hostname
resolves to http://localhost:9998
. If no property exists then the place holder remains in place i.e. ${SYSTEM.PROPERTY:hostname}
The value of hostname can be provided at runtime using –Dhostname=http://localhost:9998
as the command line argument.
Like properties in the Java platform, environment variables are key/value pairs, where both the key and the value are strings.
The conventions for setting and using environment variables vary between operating systems, and also between command line interpreters.
To get a specific environment variable you can use System.getenv(String name)
.
Environment variables are immutable.
{
"scenarioName": "Environment Variable for host name",
"steps": [
{
"name": "get_api_call",
"url": ${SYSTEM.ENV:HOSTNAME}/test/123",
...
}
]
}
To use System Environment or System properties depends on the scope of the variable and the use case.
System properties can be used to define hostname, port etc where the developer/tester can run the test(s) against different ports(8080, 8090 etc) or different hosts(dev, sit, uat, preprod etc), typically in Jenkins pipeline by maven runtime args via -D
.
Using Environment Variables, the same application can be deployed to multiple machines to run different instances and can be configured at the Operating System level, AWS, Azure Consoles; removing the need to rebuild the application to update config only.
Hence, using Environment variables to store information like username, password etc can be useful where the data might change during the runtime.
We have learnt here how to use the system properties and system env variables. Visit these issues to explore more about their usecases. Issue # 282 Issue # 248
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...