Skip to content

Commit e5ba77d

Browse files
authored
Merge branch 'main' into main
Signed-off-by: Animesh Pathak <[email protected]>
2 parents e56a3e1 + 3d1c716 commit e5ba77d

File tree

3 files changed

+175
-19
lines changed

3 files changed

+175
-19
lines changed

Diff for: sidebars.js

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = {
1111
"keploy-explained/how-keploy-works",
1212
"keploy-explained/why-keploy",
1313
"keploy-explained/faq",
14+
"keploy-explained/common-errors",
1415
],
1516
},
1617
{

Diff for: versioned_docs/version-2.0.0/keploy-explained/faq.md

+32-19
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,56 @@ tags:
99

1010
Let's get to the heart of Keploy with some fun Q&A!
1111

12-
### 1. Is Keploy a unit testing framework?
12+
### 1. What is Keploy?
1313

14-
Nope, doesn't replace your trusty unit testing frameworks like `go-test`, `JUnit`, `Pytest`, or `Jest`. Instead, it teams up with them to make your testing life a breeze, ensuring compatibility with your favorite tools and pipelines.
14+
Keploy is an open-source testing platform designed to automatically generate test cases from existing API traffic. It allows users to record, replay, and compare API interactions, making it easier to write and maintain test suites.
1515

16-
### 2. Does Keploy replace unit tests entirely?
16+
### 2. How does Keploy work?
1717

18-
Almost! Keploy aims to save you a whopping 80% of the testing effort. While it handles most cases, you might still want to write tests for some methods that aren't API-invokable.
18+
Keploy works by recording incoming API calls during normal operations. It then replays these interactions in a test environment and compares the results to the initial responses to detect regressions or unexpected behavior in the code.
1919

20-
### 3. What code changes do I need to do?
20+
### 3. Does Keploy support mocking?
2121

22-
Zero, zip, nada! For `Golang`, `Java`, `Python`, and `JavaScript` applications, Keploy plays nice with your existing codebase, requiring no code changes.
22+
Yes, Keploy allows mocking external dependencies like databases and third-party services during test execution to ensure that tests run in isolation without relying on external systems.
2323

24-
### 4. How do I run keploy in my CI pipeline?
24+
### 4. What are the prerequisites for using Keploy?
2525

26-
Simple as pie. No need to overhaul your CI pipeline; you can keep using the one that runs your unit tests. Keploy fits right in!
26+
To use Keploy, you need:
2727

28-
### 5. Does Keploy support read after write to DB scenarios?
28+
- A service or application that exposes APIs (e.g., REST or GraphQL).
29+
- Keploy supports programming languages like Go, Node.js, Python, and Java, so the appropriate SDK for your environment should be installed.
2930

30-
Absolutely! Keploy keeps things in order, recording write and read requests in sequence. It expects your application to play by the rules and serves up the same database responses as it did during capture.
31+
### 5. Is Keploy suitable for microservices architecture?
3132

32-
### 6. How does keploy handle fields like timestamps, random numbers (eg: uuids)?
33+
Yes, Keploy is designed to work in microservices-based environments. It can record and replay API calls across services, making it ideal for testing distributed systems.
3334

34-
Keploy's got a keen eye for detail. If a request passes its deduplication algorithm, it's game time. Keploy sends a second request with the same parameters to check for differences in responses. Fields like timestamps and UUIDs get the spotlight as they're automatically flagged for comparison. From then on, they're out of the testing picture.
35+
### 6. Does Keploy require code changes to integrate?
3536

36-
### 7. Can I use keploy to generate tests from production environments automatically?
37+
Keploy can be integrated without any changes to the application code. However, adding Keploy SDKs may offer more fine-grained control for specific use cases.
3738

38-
Not just yet, but we're on it! We're cooking up a scalable deduplication algorithm to make it safe for production. If you're itching to explore this frontier, come chat with us on Slack. We'd love to join forces and put our system to the test with your systems.
39+
### 7. Can Keploy help with CI/CD pipelines?
3940

40-
### 8. What if my application behaviour changes?
41+
Yes, Keploy integrates with CI/CD pipelines to run automated tests on every commit or code change. This ensures that any regressions are detected early in the development process.
4142

42-
Change is the only constant in the tech world, right? If your app decides to switch things up, your test cases might break. No worries; you can mark the new behavior as normal.
43+
### 8. Is Keploy scalable for large projects?
4344

44-
Got more questions? We're all ears (and code)👂.
45+
Keploy is designed to be scalable. It can handle high traffic volumes and complex services in large-scale distributed systems. It is efficient for generating and managing test cases across services.
4546

46-
<!-- ### 9. Would keploy know if an external service changes?
47+
### 9. Does Keploy support testing legacy applications?
4748

48-
Not yet. Unless that application is also using keploy, keploy would only test the functionality of the current application. We are working to detect scanning for API contract violations and adding multiple application to perform comprehensive integration tests. All contributions are welcome. -->
49+
Yes, Keploy can be used to test legacy systems, especially if they expose APIs. It can record traffic and replay calls without needing to modify the legacy codebase.
50+
51+
### 10. Can Keploy be used with databases?
52+
53+
Yes, Keploy can mock database responses during test replay. This helps isolate tests and ensures consistency during test execution.
54+
55+
### 11. Is Keploy free to use?
56+
57+
Yes, Keploy is open-source and free to use under the Apache 2.0 license. You can also contribute to its development on GitHub.
58+
59+
### 12. Can I customize Keploy's behavior for specific APIs?
60+
61+
Yes, Keploy provides configuration options to customize recording, replay, and comparison logic for specific APIs, giving users control over how their APIs are tested.
4962

5063
Hope this helps you out, if you still have any questions, reach out to us .
5164

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
---
2+
id: keploy-karaf-example
3+
title: Setting Up Keploy Agent in Apache Karaf for Local Development
4+
sidebar_label: Keploy Karaf Example
5+
description: This section documents how to run keploy with Karaf
6+
tags:
7+
- keploy
8+
- keploy karaf
9+
keywords:
10+
- keploy
11+
- documentation
12+
- running-guide
13+
---
14+
15+
## Step 1: Download Required JARs
16+
17+
Use `wget` to download the necessary JAR files:
18+
19+
- [KeployAgent.jar](https://keploy-enterprise.s3.us-west-2.amazonaws.com/agent-jars/KeployAgent.jar)
20+
- [org.jacoco.agent-0.8.12-runtime.jar](https://keploy-enterprise.s3.us-west-2.amazonaws.com/agent-jars/org.jacoco.agent-0.8.12-runtime.jar)
21+
22+
Run the following commands to download the files:
23+
24+
```bash
25+
wget https://keploy-enterprise.s3.us-west-2.amazonaws.com/agent-jars/KeployAgent.jar
26+
wget https://keploy-enterprise.s3.us-west-2.amazonaws.com/agent-jars/org.jacoco.agent-0.8.12-runtime.jar
27+
```
28+
29+
## Step 2: Configure Apache Karaf
30+
31+
### Update `JAVA_OPTS` for Linux/Mac in `setenv` File
32+
33+
1. Navigate to the `bin` directory of your Apache Karaf installation.
34+
2. Open the `setenv` file for editing.
35+
3. Add the paths of the downloaded agents under the `JAVA_OPTS` section. For example:
36+
37+
```bash
38+
export JAVA_OPTS="-javaagent:/path/to/KeployAgent.jar"
39+
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"
40+
```
41+
42+
### Update `JAVA_OPTS` for Windows in `setenv.bat` File
43+
44+
1. Navigate to the `bin` directory of your Apache Karaf installation.
45+
2. Open the `setenv.bat` file for editing.
46+
3. Add the paths of the downloaded agents under the `JAVA_OPTS` section. For example:
47+
48+
```bat
49+
set JAVA_OPTS=-javaagent:/path/to/KeployAgent.jar
50+
set JAVA_OPTS=%JAVA_OPTS% -javaagent:/path/to/org.jacoco.agent-0.8.12-runtime.jar=address=*,port=36320,destfile=jacoco-it.exec,output=tcpserver
51+
```
52+
53+
### Set Environment Variables as Java System Properties on Windows
54+
55+
On Windows, all environment variables should be passed as `-D` system properties for Java. Update the `JAVA_OPTS` section in `setenv.bat` to include the required variables. For example:
56+
57+
```bat
58+
set JAVA_OPTS=%JAVA_OPTS% -DAPI_KEY=xRp5nyiQ+B6yltBUpw==
59+
set JAVA_OPTS=%JAVA_OPTS% -DKEPLOY_MODE=RECORD
60+
set JAVA_OPTS=%JAVA_OPTS% -javaagent:/path/to/org.jacoco.agent-0.8.12-runtime.jar=address=*,port=36320,destfile=jacoco-it.exec,output=tcpserver
61+
```
62+
63+
Replace the placeholder values with actual paths and keys as needed.
64+
65+
### Update `config.properties`
66+
67+
1. Navigate to the `etc/config.properties` file in your Karaf installation.
68+
2. Add the following entries under the `bootdelegation` section to allow OSGi bundles to access Keploy artifacts:
69+
70+
```properties
71+
org.osgi.framework.bootdelegation = \
72+
... \
73+
io.keploy.*, \
74+
javax.servlet, \
75+
javax.servlet.http
76+
```
77+
78+
## Step 3: Export Environment Variables
79+
80+
1. Export the API key specific to your user, as mentioned on [Keploy's User Dashboard](https://app.keploy.io/users), which is required for Keploy to function, by running the following command in the same terminal session:
81+
82+
```bash
83+
export API_KEY="<API_KEY>"
84+
```
85+
86+
Replace the `API_KEY` value with your actual API key if different.
87+
88+
2. Export the application path to point to your target folder containing Java classes:
89+
90+
```bash
91+
export APP_PATH="/Users/path/to/karaf-sample/user-service"
92+
```
93+
94+
Replace the `APP_PATH` value with the absolute path to your application's target folder.
95+
96+
## Step 4: Record Test Cases
97+
98+
1. Restart Apache Karaf by setting the environment variable `KEPLOY_MODE` to `RECORD`:
99+
100+
```bash
101+
export KEPLOY_MODE="RECORD"
102+
./karaf
103+
```
104+
105+
2. Record test cases using the following command:
106+
107+
```bash
108+
keploy record --base-url="http://localhost:8181"
109+
```
110+
111+
3. Make a series of API calls to your application's endpoints.
112+
4. After completing the API calls, press `Ctrl+C` in the session where you are running the Keploy binary to stop recording.
113+
114+
## Step 5: Or Use Import Postman Collection
115+
116+
1. Ensure you have a Postman collection ready for your application.
117+
2. Run the following command to import the Postman collection as Keploy tests:
118+
119+
```bash
120+
keploy import postman --path="/path/to/YourPostmanCollection.json"
121+
```
122+
123+
Replace `/path/to/YourPostmanCollection.json` with the actual path to your Postman collection.
124+
125+
## Step 6: Run Keploy Tests
126+
127+
1. Restart Apache Karaf by setting the environment variable `KEPLOY_MODE` to `test`:
128+
129+
```bash
130+
export KEPLOY_MODE="test"
131+
./karaf
132+
```
133+
134+
2. Use the following command to run the imported tests:
135+
136+
```bash
137+
keploy test --base-path="http://localhost:8181"
138+
```
139+
140+
This assumes your Karaf application is running locally on port 8181.
141+
142+
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.

0 commit comments

Comments
 (0)