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:
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.
- Git - to clone the project (or you could just download the source code as a ZIP file)
- Java JDK - (at least version 17 or greater), OpenJDK also works
JAVA_HOME
environment variable set
- 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
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
.
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 |
In the commands below,
mvn
will work if you have Maven installed. Else replace it with./mvnw
ormvnw
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.
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:
Documentation: Karate API Testing
Documentation: Karate UI Testing
- mock/test.feature - this would run the API test after starting the mock defined in mock.feature.
- Note how the same test (simple.feature) works for both the "real" API and the mock.
Documentation: Karate API Mocks
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