Skip to main content
Version: 1.0.0

Replay Tests & Mocks for Go (v1.0.0)

To run KTests and KMocks you can follow any one of these methods:

Method 1

Set Environment Variable KEPLOY_MODE

export KEPLOY_MODE="test"

Run application and find test report summary on the Keploy Server Logs and detailed test report in directory where Keploy Server is running.

Test report summary

Method 2 [preferred]

Testing using Unit Test File

Add this go unit test file main_test.go in the root of your application.

  package main

import (
"github.com/keploy/go-sdk/keploy"
"testing"
)

func TestKeploy(t *testing.T) {
keploy.SetTestMode()
go main()
keploy.AssertTests(t)
}

Let's run the test-file.

 go test -coverpkg=./... -covermode=atomic  ./...

output should look something like -

ok      test-app-url-shortener  6.268s  coverage: 80.3% of statements in ./...

You'll see the total test-coverage of Keploy recorded test-cases and previously written unit-test cases(if any).

You can use this unit-test file and there's no-need to add any additional steps/checks in your CI pipeline.

Method 3

Run Tests in CI/CD

After following METHOD 2 above ^, Keploy will be integrated to go-test. If you already have go-test no changes are required in the CI/CD pipeline.