-
-
Notifications
You must be signed in to change notification settings - Fork 406
Testing Kotlin Application using Zerocode
Testing an API should always be easy irrespective of the language API is written with.
ZeroCode framework make sure that you spend zero focus on the tools and technology for structuring or building your test strategy and rather ZeroCode enables you and your team to spend 100% of your time in thinking about application test scenarios, various use cases/functionalities so that you get best out of you project delivery.
With this point in mind, if you are building your API in Kotlin and you want to write integration tests, Performance test, Load Test etc for your API then, as I mentioned above, it's all very easy.
This wiki page, details out high level pointers with examples, how easy is to test with ZeroCode, an API written in Kotlin with Spring Boot. Complete Project code along with Kotlin general concepts are given below.
Let's say we have an API which exposes three REST end points written in Kotlin
1) GET - Fetch All runners profile
2) POST - Create runner profile
3) PATCh- update (few attributes) runner profile
The obvious thing to test any API is to validate the API contract for happy and negative scenarios and assert the expected response in both ( happy and negative ) the cases.
Steps to write ZeroCode Test scripts for Kotlin API.
Step 1:-
Write a Kotlin class for a functionality you want to test.
Step 2:-
Write the test scripts in simple json steps
That's all and DONE. Relax!!
Let's start with writing our first test for 1st API end point
1) GET end point - Fetch All runners profile.
Step 1:- Create a Kotlin class named "TestGetOperations.kt"
If you notice, there is no code actually in your @Test method!! Making your life easy.
@TargetEnv("application_host.properties")
@RunWith(ZeroCodeUnitRunner::class)
class TestGetOperations {
@Test
@JsonTestCase("integration_tests/get/get_all_runners.json")
fun test_get_all_runners() {
}
}
Step 2:- Write the test scripts in simple json steps. Create a test script file named "get_all_runners.json"
If you notice below, it is simple json steps, so irrespective of language you can very well write your test cases in simplest ever way possible.
{
"scenarioName": "Get All Runners @@Neeraj",
"steps": [
{
"name": "get_all_runners",
"url": "/parkrun/runners/",
"operation": "GET",
"request": {
},
"assertions": {
"status": 200,
"body": {
"_embedded.runners.SIZE": "$GT.0",
"_embedded.runners[0]._links.self.href": "$NOT.NULL"
}
}
}
]
}
That's it and ALL DONE.
I am sure, it will now be very easy for you to write test cases on your own for other end points I listed earlier.
- POST - Create runner profile
- PATCh - update (few attributes) runner profile
The complete project code along with detailed explanation can be referred here Kotlin-Spring Boot API
Detailed post about Kotlin general Concepts can be read here Kotlin Concepts and Spring Boot Kotlin API
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...