You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(mocklib): fixed false positive file existence checks for mocks in mockLib (#138)
- While recording mocks using mockLib, it was showing that mock already exists since functionality
was checking only folder name and not the actual file in the path.
Signed-off-by: gouravkrosx <gouravgreatkr@gmail.com>
-**Off**: Turns off all the functionality provided by the API
62
+
63
+
**Note:**`KEPLOY_MODE` value is case sensitive.
64
+
65
+
56
66
## Usage
57
67
58
68
-**Start keploy server [refer](https://github.com/keploy/keploy#start-keploy-server)**
@@ -77,11 +87,12 @@ or to *build.gradle*:
77
87
- Download the latest - Download the latest agent jar
78
88
from [here](https://search.maven.org/artifact/io.keploy/keploy-sdk/1.2.8/jar) (eg: 1.2.8)
79
89
80
-
- Prefix `-javaagent:` with absolute classpath of agent jar (eg: `-javaagent:<your full path to agent jar>/agent-1.2.8.jar`).
90
+
- Prefix `-javaagent:` with absolute classpath of agent jar (
91
+
eg: `-javaagent:<your full path to agent jar>/agent-1.2.8.jar`).
81
92
82
-
1. **Using Intellij:** Go to Edit Configuration-> add VM options -> paste _java agent_ edited above.
93
+
1. **Using Intellij:** Go to Edit Configuration-> add VM options -> paste _java agent_ edited above.
83
94
84
-
2. **Using Command Line :**
95
+
2. **Using command line:**
85
96
- First add below plugins in your *pom.xml* file.
86
97
```xml
87
98
<plugin>
@@ -114,8 +125,11 @@ or to *build.gradle*:
114
125
</configuration>
115
126
</plugin>
116
127
```
117
-
- And then run this command:`java -javaagent:<your full path to agent jar>/agent-1.2.8.jar -jar <your full path to application jar>.jar`. This command will attach agent jar and also run the application. You need to set some required env variables written below in order to generate test cases. So, run this command after setting the env variables.
118
-
128
+
- And then run this
129
+
command:`java -javaagent:<your full path to agent jar>/agent-1.2.8.jar -jar <your full path to application jar>.jar`
130
+
. This command will attach agent jar and also run the application. You need to set some required env
131
+
variables written below in order to generate test cases. So, run this command after setting the env
132
+
variables.
119
133
120
134
121
135
- **Configure Environment Variables**
@@ -130,11 +144,11 @@ or to *build.gradle*:
130
144
- `DENOISE` (default DENOISE = false)
131
145
**Note:** By enabling denoise, it will filter out noisy fields for the testcase.
**Note:** It is used to maintain the same database state.
147
+
**Note:** It is used to maintain the same database state when mocking is disabled.
134
148
135
149
136
150
- **Generate testcases**
137
-
- To generate/capture TestCases set and run your application.
151
+
- To generate/capture TestCases set and run your application.
138
152
1. Set `KEPLOY_MODE = record` (default "off")
139
153
2. Run your application.
140
154
3. Make some API calls.
@@ -143,51 +157,57 @@ or to *build.gradle*:
143
157
- **Note:** Before running tests stop the sample application.
144
158
145
159
- Set `KEPLOY_MODE = test` (default "off")
146
-
- Using IDE
160
+
- **Using IDE:** _(for local use-case we prefer running tests via IDE)_
147
161
1. Run your application.
148
162
2. You can also run the application with coverage to see the test coverage.
149
163
150
-
- Using command line
151
-
1. Add below code in your testfile and run `mvn test -DargLine="-javaagent:<your full path to agent jar>.jar"`.
152
-
153
-
```java
154
-
@Test
155
-
public void TestKeploy() throws InterruptedException {
164
+
- If you want to run keploy tests along with other unit testcases. You will be required to set the `javaagent` again in your test profile just like below.
5. Run your tests using command : `mvn test -DargLine="-javaagent:<your full path to agent jar>.jar"
228
-
`.
229
-
230
-
231
-
### KEPLOY_MODE
232
-
There are 3 modes:
233
-
- **Record**: Sets to record mode.
234
-
- **Test**: Sets to test mode.
235
-
- **Off**: Turns off all the functionality provided by the API
236
-
237
-
**Note:** `KEPLOY_MODE` value is case sensitive.
238
-
247
+
- Run your tests using command : `mvn test`.
248
+
249
+
## Want stubs for unit test cases as well?
250
+
- Java-sdk also supports mocking feature for unit testcase, where you write your own unit test cases and use keploy generated mocks as stubs.
251
+
252
+
### Usage
253
+
- Set `javaagent` in your unit test file configuration.
254
+
- You just need to set the name of the mock as shown below.
255
+
```java
256
+
@Test
257
+
public void testHttpCall() throws Exception {
258
+
new MockLib("okhttpCall"); //setting name of the mock
259
+
``` your unit test case code goes here ```
260
+
}
261
+
```
262
+
- You can also provide location where your mocks can be stored using `KEPLOY_MOCK_PATH`. (default **/src/test/e2e/mocks** directory of your application)
263
+
264
+
265
+
-**Generate mocks**
266
+
1. Record mocks by setting `KEPLOY_MODE=record` and run your test file.
267
+
2. You will be able to see _editable_ and _readable_ mocks at your provided location.
268
+
-**Run your unit testcases**
269
+
1. Just set `KEPLOY_MODE=test`, run your test file and you are good to go.
270
+
271
+
#### 🤩 See, you didn't even need to create a stub for your unit test cases, it's all generated using the java-sdk mock library.
logger.info("Keploy created new mocking context in {} mode {}.If you dont see any logs about your dependencies below, your dependency/s are NOT wrapped.", mode, name);
0 commit comments