Skip to content

karatelabs/karate-todo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

This is a self-contained project that is great for training or demo-ing all capabilities of Karate. It includes an app that has a working front-end UI and back-end API. Examples of API tests, API performance tests, API mocks and Web-Browser automation are included.

An 8 minute video ideal for beginners can be found here. Karate Kick Start - The TODO Sample and Demo Project. No programming or automation experience is required.

A longer video (20 minutes) which is a good introduction to Karate uses demos in this project and can be an additional reference: API Testing with Karate.

Use the official Karate IDE plugins for the best developer experience:

Instructions

You can use GitHub Codespaces to open this project directly in your browswer ! The default image includes Java and Maven, so you can skip the "Prerequisites" section below and go directly to Verify Setup. Make sure you install the Karate extension for Visual Studio Code in your Codespace. The Karate extension for VS Code can also be run in a Docker based devcontainer.

Prerequisites

Get Source Code

  • open a terminal in a folder in which karate-todo will be created
  • enter the following command: git clone https://github.com/karatelabs/karate-todo.git

Download Code as ZIP

If you don't have Git installed, you can download the source code as a ZIP file and extract it. The folder you get may be called karate-todo-main, so just re-name it to karate-todo.

Verify Setup

Open a terminal in the directory called karate-todo.

If the following command runs the ApiTest fine, you are all set:

Windows Linux / Mac
mvnw clean test ./mvnw clean test

Running karate-todo

In the commands below, mvn will work if you have Maven installed. Else replace it with ./mvnw or mvnw like shown above to use the Maven wrapper.

Now you can run the LocalRunner class as JUnit test. You can do this from an IDE that has Java support.

Or from the command-line:

mvn clean test -Dtest=LocalRunner

Now you should see the front-end at http://localhost:8080

To stop, just kill the process or stop the Java process from the IDE.

Running Tests

After the app has been started on localhost:8080, you can run tests.

One of the easiest ways to run tests, recommended for non-programmers or teams that are not familiar with Java, is to use Visual Studio Code.

There are more tests and examples in this project, but the following are the simplest ones to get started with:

API Test

Documentation: Karate API Testing

UI Test

Documentation: Karate UI Testing

API Mock

Documentation: Karate API Mocks

API Performance Test

To run performance test (after the app has been started on localhost):

mvn test -P gatling

The above command uses Maven and has to be run on the command-line. The entry point is perf/TodoSimulation.java. The Maven pom.xml has a <profile> called gatling, which sets up the performance test.

Note that the new Java DSL for Gatling is being used instead of Scala.

The karate-gatling dependency in the pom.xml in test scope, can bring in a lot of extra dependencies because of Gatling, so you may have to use the Karate "fat-jar". Also consider having your Karate tests in a separate Maven module if there are too many conflicts between libraries you already have in test scope with the ones that Karate (and Gatling) may bring in.

Documentation: Karate API Performance Testing

Gradle

A sample build.gradle and instructions can be found here.

About

Self-contained demo of all Karate core capabilities

Resources

Stars

Watchers

Forks