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
Copy file name to clipboardexpand all lines: README.md
+60-1
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,7 @@ This is the client SDK for the [Keploy](https://github.com/keploy/keploy) testin
7
7
1.[Installation](#installation)
8
8
2.[Usage](#usage)
9
9
3.[Mocking/Stubbing for unit tests](#mockingstubbing-for-unit-tests)
10
+
4.[Code coverage by the API tests](#code-coverage-by-the-api-tests)
10
11
11
12
## Installation
12
13
@@ -16,6 +17,10 @@ go get -u github.com/keploy/go-sdk/v2
16
17
17
18
## Usage
18
19
20
+
### Get coverage for keploy automated tests
21
+
The code coverage for the keploy API tests using the `go-test` integration.
22
+
Keploy can be integrated in your CI pipeline which can add the coverage of your keploy test.
23
+
19
24
### Create mocks/stubs for your unit-test
20
25
21
26
These mocks/stubs are realistic and frees you up from writing them manually. Keploy creates `readable/editable` mocks/stubs yaml files which can be referenced in any of your unit-tests tests. An example is mentioned in [Mocking/Stubbing for unit tests](#mockingstubbing-for-unit-tests) section
@@ -32,7 +37,7 @@ import(
32
37
...
33
38
err:= keploy.New(keploy.Config{
34
39
Mode: keploy.MODE_RECORD, // It can be MODE_TEST or MODE_OFF. Default is MODE_TEST. Default MODE_TEST
35
-
Name: "<stub_name/mock_name>"// TestSuite name to record the mock or test the mocks
40
+
Name: "<stub_name/mock_name>"// TestSuite name to record the mock or test the mocks
36
41
Path: "<local_path_for_saving_mock>", // optional. It can be relative(./internals) or absolute(/users/xyz/...)
37
42
MuteKeployLogs: false, // optional. It can be true or false. If it is true keploy logs will be not shown in the unit test terminal. Default: false
38
43
delay: 10, // by default it is 5 . This delay is for running keploy
The percentage of code covered by the recorded tests is logged if the test cmd is ran with the go binary and `withCoverage` flag. The conditions for the coverage is:
154
+
1. The go binary should be built with `-cover` flag.
155
+
2. The application should have a graceful shutdown to stop the API server on `SIGTERM` or `SIGINT` signals. Or if not call the **GracefulShutdown** from the main function of your go program. Ex:
156
+
```go
157
+
funcmain() {
158
+
159
+
port:="8080"
160
+
161
+
r:= gin.Default()
162
+
163
+
r.GET("/:param", getURL)
164
+
r.POST("/url", putURL)
165
+
// should be called before starting the API server from main()
166
+
keploy.GracefulShutdown()
167
+
168
+
r.Run()
169
+
}
170
+
```
171
+
The keploy test cmd will look like:
172
+
```sh
173
+
keploy test -c "PATH_TO_GO_COVER_BIANRY" --withCoverage
174
+
```
175
+
The coverage files will be stored in the directory.
0 commit comments