Skip to content

Commit c1e8488

Browse files
officialasishkumaractions-user
authored andcommitted
feat: add docs for dedup
Signed-off-by: Asish Kumar <[email protected]>
1 parent 4bfad0a commit c1e8488

File tree

1 file changed

+20
-126
lines changed

1 file changed

+20
-126
lines changed

versioned_docs/version-3.0.0/keploy-cloud/deduplication.md

Lines changed: 20 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ keywords:
1111
- keploy cloud
1212
- deduplication
1313
- duplicate tests
14-
- python
15-
- java
16-
- nodejs
17-
- node
14+
- golang
1815
- testcases
1916
---
2017

@@ -29,161 +26,58 @@ It simplifies the testing process by removing redundant test cases, which saves
2926
To detect duplicate tests, simply run the below command, like so:
3027

3128
```bash
32-
keploy dedup -c "<CMD_TO_RUN_APP>" -t="<TESTSETS_TO_RUN>"
29+
keploy test -c "docker compose up" --containerName containerName --dedup
3330
```
3431

35-
### For Node Applications
32+
### For Golang Applications
3633

37-
**1. Pre-requsite**
34+
**1. Pre-requisite**
3835

39-
Install the `keploy/sdk` and `nyc` package : -
36+
Install the `keploy/go-sdk/v3/keploy` : -
4037

4138
```bash
42-
npm i @keploy/sdk [email protected]
39+
go get github.com/keploy/go-sdk/v3/keploy
4340
```
4441

45-
Add the the following on top of your main application js file (index.js/server.js/app.js/main.js) : -
42+
Add the following on top of your main application file : -
4643

4744
```bash
48-
const kmiddleware = require('@keploy/sdk/dist/v2/dedup/middleware.js')
49-
50-
app.use(kmiddleware())
51-
```
52-
53-
**2. Run Deduplication**
54-
55-
```
56-
keploy dedup -c "<CMD_TO_RUN_APP>" --delay 10 -t="<TESTSETS_TO_RUN>"
45+
import _ "github.com/keploy/go-sdk/v3/keploy"
5746
```
5847

59-
#### Example
60-
61-
Let's use the [expresss-mongoose](https://github.com/keploy/samples-typescript/tree/main/express-mongoose) application to test dedup feature. In our `src/app.js` file we need to have imported and initialized `@keploy/sdk` package, so now let's run the de-duplication command to check : -
48+
Update the go build command in Dockerfile to add new flags which is required for deduplication (this is not required for native)
6249

6350
```bash
64-
keploy dedup -c "node src/app.js" -t "test-set-1"
65-
```
66-
67-
<img width="1060" alt="image" src="https://github.com/keploy/docs/assets/53110238/641ded9d-c75f-4861-aafd-bc0f2bbeda7f" />
68-
69-
Voila! Keploy will now detect duplicate tests .
70-
71-
### For Java Applications
72-
73-
**1. Pre-requsite**
74-
75-
Put the latest keploy-sdk in your pom.xml file : -
76-
77-
```xml
78-
<dependency>
79-
<groupId>io.keploy</groupId>
80-
<artifactId>keploy-sdk</artifactId>
81-
<version>0.0.1-SNAPSHOT</version>
82-
</dependency>
83-
```
84-
85-
Now that we have added keploy-sdk, let's import it in our main class : -
86-
87-
```java
88-
import io.keploy.servlet.KeployMiddleware;
89-
90-
@Import(KeployMiddleware.class)
91-
public class SamplesJavaApplication {
92-
public static void main(String[] args) {
93-
SpringApplication.run(SamplesJavaApplication.class, args);
94-
}
95-
}
51+
RUN go build -cover -covermode=atomic -coverpkg=./... -o /app/main .
9652
```
9753

9854
**2. Run Deduplication**
9955

100-
We need to create Jar file via : -
56+
For Docker, run:
10157

10258
```bash
103-
mvn clean install -DskipTests
59+
keploy test -c "docker compose up" --containerName containerName --dedup
10460
```
10561

106-
Once we have our jar file ready, we can run following command : -
62+
For Native, run:
10763

10864
```bash
109-
keploy dedup -c "java -javaagent:<PATH_TO_JacocoAgent>=address=*,port=36320,destfile=jacoco-it.exec,output=tcpserver -jar <PATH_TO_JAR_FILE>" --delay 10 -t="test-set-0"
65+
keploy test -c ./main --dedup
11066
```
11167

112-
Voila! Keploy will now detect duplicate tests .
113-
114-
### For Python Applications
115-
116-
Deduplication works only on test mode there are no special instructions to record your tests.
68+
where `./main` is the binary produced by doing `go build -cover -covermode=atomic -coverpkg=./... -o ./main .`
11769

118-
**1. Pre-requsite**
70+
This will generate a dedupData.yaml file
11971

120-
Put the latest keploy-sdk in your file : -
72+
After this Run
12173

12274
```bash
123-
pip install keploy coverage requests fastapi
75+
keploy dedup
12476
```
12577

126-
In your main app file add the following with along with the other imports. And add Keploy's middleware along with the other middlewares for your app based on your framework:
127-
128-
1. In FastAPI -
129-
130-
```py
131-
# existing imports
132-
from keploy import FastApiCoverageMiddleware
133-
134-
app.add_middleware(FastApiCoverageMiddleware)
135-
# existing functions
136-
```
137-
138-
2. In Flask -
139-
140-
```py
141-
# existing imports
142-
from keploy import FlaskCoverageMiddleware
143-
144-
app.wsgi_app = FlaskCoverageMiddleware(app.wsgi_app)
145-
146-
# existing functions
147-
```
148-
149-
3. In Django - Open `settings.py` and add the middleware class to the **MIDDLEWARE** list.
150-
151-
```py
152-
MIDDLEWARE = [
153-
'django.middleware.security.SecurityMiddleware',
154-
'django.contrib.sessions.middleware.SessionMiddleware',
155-
'django.middleware.common.CommonMiddleware',
156-
'django.middleware.csrf.CsrfViewMiddleware',
157-
'django.contrib.auth.middleware.AuthenticationMiddleware',
158-
'django.contrib.messages.middleware.MessageMiddleware',
159-
'django.middleware.clickjacking.XFrameOptionsMiddleware',
160-
'keploy.DjangoCoverageMiddleware', # Add keploy middleware here
161-
],
162-
163-
# Other settings
164-
```
165-
166-
**2. Run Deduplication**
167-
168-
Run keploy with test-sets in which you want to check for the duplicate testcases :
169-
170-
```sh
171-
keploy dedup -c "<command to run your Python app>" --delay "<time required for your application to start>"
172-
```
173-
174-
#### Example
175-
176-
Let's use the [flask-mongo](https://github.com/keploy/samples-python/tree/main/flask-mongo) application to test dedup feature. In our `app.py` file we need to have imported and initialized `keploy` package, since this is a flask application we can follow above flask approach. Once we have added package, let's run the de-duplication command to check : -
177-
178-
```bash
179-
keploy dedup -c "python3 app.py" -t "test-set-1"
180-
```
181-
182-
<img width="1111" alt="image" src="https://github.com/user-attachments/assets/03638c80-ae11-492f-9b4e-bce92d15a04e"/>
183-
184-
## Remove Duplicate Tests
78+
This command will create a duplicates.yaml file which will contain all the test cases which was found to be duplicate.
18579

186-
You can simply remove duplicate tests with :
80+
In order to remove all the duplicate test cases, run the following command:
18781

18882
```bash
18983
keploy dedup --rm

0 commit comments

Comments
 (0)