Setting Up Keploy Agent in Apache Karaf for Local Development
Step 1: Download Required JARs and Keploy Version
Pre-requisites
- Linux kernel 5.15 or higher
- Tested with distributions:
- Fedora 40+
- Ubuntu 22.04+
- Debian 12+
- Tested with JDK 1.8 to 17 and Karaf 4.3.x
Install Keploy Binary
Use Keploy's one-click installation to download and install the latest Keploy binary:
curl --silent -O -L https://keploy.io/ent/install.sh && source install.sh
Download Required JARs
Use wget
to download the necessary JAR files:
Run the following commands to download the files:
wget https://keploy-enterprise.s3.us-west-2.amazonaws.com/agent-jars/io.keploy.agent-2.0.1.jar
wget https://keploy-enterprise.s3.us-west-2.amazonaws.com/agent-jars/org.jacoco.agent-0.8.12-runtime.jar
Step 2: Configure Apache Karaf
Update JAVA_OPTS
for Linux in setenv
File:
-
Navigate to the
bin
directory of your Apache Karaf installation. -
Open the
setenv
file for editing. -
Add the paths of the downloaded agents under the
JAVA_OPTS
section. For example:export JAVA_OPTS="-javaagent:/path/to/io.keploy.agent-2.0.1.jar"
export JAVA_OPTS="$JAVA_OPTS -javaagent:/path/to/org.jacoco.agent-0.8.12-runtime.jar=address=*,port=36320,destfile=jacoco-it.exec,output=tcpserver"
Replace the placeholder values with actual paths and keys as needed.
Step 3: Export Environment Variables
-
Export the API key specific to your user, as mentioned on Keploy's User Dashboard, which is required for Keploy to function, by running the following command in the same terminal session:
export KEPLOY_API_KEY="<KEPLOY_API_KEY>"
Replace the
KEPLOY_API_KEY
value with your actual API key if different. -
Export the application path to point to your target folder containing Java classes:
export KEPLOY_APP_UNDER_TEST_PATH="/Users/path/to/karaf-sample/user-service"
Replace the
KEPLOY_APP_UNDER_TEST_PATH
value with the absolute path to your application's target folder (Where Java compiled classes are present).
Step 4: Record Test Cases
-
Start the karaf environment
bin/karaf
-
Record test cases using the following command:
keploy record --base-path="http://localhost:8181"
-
Make a series of API calls to your application's endpoints.
-
After completing the API calls, press
Ctrl+C
in the session where you are running the Keploy binary to stop recording.
Step 5: Or Use Import Postman Collection
-
Ensure you have a Postman collection ready for your application.
-
Run the following command to import the Postman collection as Keploy tests:
keploy import postman --path="/path/to/YourPostmanCollection.json"
Replace
/path/to/YourPostmanCollection.json
with the actual path to your Postman collection.
Step 6: Run Keploy Tests
-
Use the following command to run the imported tests:
keploy test --base-path="http://localhost:8181"
This assumes your Karaf application is running locally on port 8181.
After running the tests, a coverage.xml
file will be generated in the root directory of your project. This file contains the test coverage report, which can be used for further analysis or integrated with CI/CD pipelines.