Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Writing API Tests with Karate

You're reading from   Writing API Tests with Karate Enhance your API testing for improved security and performance

Arrow left icon
Product type Paperback
Published in May 2023
Publisher Packt
ISBN-13 9781837638260
Length 326 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Benjamin Bischoff Benjamin Bischoff
Author Profile Icon Benjamin Bischoff
Benjamin Bischoff
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Part 1:Karate Basics
2. Chapter 1: Introducing Karate’s Core Concepts FREE CHAPTER 3. Chapter 2: Setting up Your Karate Project 4. Chapter 3: Writing Basic Karate Tests 5. Chapter 4: Running Karate Tests 6. Chapter 5: Reporting and Logging 7. Part 2:Advanced Karate Functionalities
8. Chapter 6: More Advanced Karate Features 9. Chapter 7: Customizing and Optimizing Karate Tests 10. Chapter 8: Karate in Docker and CI/CD pipelines 11. Chapter 9: Karate UI for Browser Testing 12. Chapter 10: Performance Testing with Karate Gatling 13. Index 14. Other Books You May Enjoy

Karate in Docker and CI/CD pipelines

As we have seen in the previous chapters, Karate is very powerful for API testing. However, so far, we have only run tests on our local systems. Also, these tests were run by us on an ad hoc basis. These are very helpful while developing applications or running tests when we want some information about the current state of APIs.

In many cases, this is not enough. Instead, these tests should be run automatically within build pipelines that typically pull the current application code and build and deploy it to a test server, test it, and continue deployment until this reaches live instances to be used in production. This process is called continuous integration/continuous deployment (CI/CD), with the goal of a completely automated build and test flow.

In any case, this must be all triggered by automation, so we don’t forget to run tests at the appropriate time. This does not mean, though, that we should not be informed about the test results if there are any problems. We could even go so far as to stop further deployment to live servers in case of issues on our test instances. Also, it is helpful if our Karate tests are run regularly against live instances of an application so we can use it for monitoring purposes.

Shift left testing

In recent times, the concept of shifting left has gained traction. This means that tests should be run at the earliest time possible. In the case of API tests, that means that they should be run as soon as a new version of an API is available on a test server. This way, it is much easier to track down what has caused issues when tests fail. Also, the correct team dealing with API development can be notified automatically and directly without delay. If all tests were run only after every part of a system was built and deployed, it would take much longer to determine which team is responsible for fixing bugs and what component caused the error.

This is usually done is by specialized build servers such as Jenkins or online platforms such as GitHub that offer this functionality.

In this chapter, we will explore different ways to run our test to suit these platforms and fulfill our requirements. It is not possible in this limited scope to give you a full step-by-step guide on how to reach a complete CI/CD setup. Rather, it is intended as a starting point to provide ideas and further learning on how to achieve this goal.

The main topics covered in this chapter are the following:

  • Triggering Karate tests from shell scripts
  • Running Karate tests in a Docker container
  • Customizing our tests
  • Integrating Karate tests into GitHub workflows
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image