Keploy is a no-code testing platform that generates tests from API calls.
This is the client SDK for Keploy API testing platform. There are 2 modes:
- Record mode
- Record requests, response and all external calls and sends to Keploy server.
- It runs the request on the API again to identify noisy fields.
- Sends the noisy fields to the keploy server to be saved along with the testcase.
- Test mode
- Fetches testcases for the app from keploy server.
- Calls the API with same request payload in testcase.
- Validates the respones and uploads results to the keploy server
The Keploy Java SDK helps you to integrate keploy with java applications. (For other languages, see KEPLOY SDKs)
- Java 1.8+
Find the latest release of the Keploy Java SDK at maven central.
Add keploy-sdk as a dependency to your pom.xml:
<dependency>
<groupId>io.keploy</groupId>
<artifactId>keploy-sdk</artifactId>
<version>N.N.N</version> (eg: 1.0.13)
</dependency>
or to build.gradle:
implementation 'io.keploy:keploy-sdk:N.N.N' (eg: 1.0.13)
-
Start keploy server refer
-
Replace
@SpringBootApplicationwith@SpringBootApplication(scanBasePackages = {"<your base package>", "io.keploy.servlet"}).in your main class. -
Configure Environment Variables
APP_NAME(default APP_NAME = myApp)APP_PORT(default APP_PORT = 8080)KEPLOY_URL(default KEPLOY_URL = http://localhost:6789/api)KEPLOY_MODE(default KEPLOY_MODE = record/test)KTESTS_PATH(default test/e2e directory of your application)DENOISE(default DENOISE = false) Note: By enabling denoise, it will filter out noisy fields for that testcases.
-
Generate testcases
- To generate/capture TestCases set and run your application.
- Set
KEPLOY_MODE = record - Run your application.
- Make some API calls.
- Set
- To generate/capture TestCases set and run your application.
-
Run the testcases
-
Note: Before running tests stop the sample application.
- Set
KEPLOY_MODE = test(default "record")-
Using IDE
- Run your application.
- You can also run the application with coverage to see the test coverage.
-
Using command line
-
Add below code in your testfile and run
mvn test.@Test public void TestKeploy() throws InterruptedException { CountDownLatch countDownLatch = HaltThread.getInstance().getCountDownLatch(); mode.setTestMode(); new Thread(() -> { SamplesJavaApplication.main(new String[]{""}); countDownLatch.countDown(); }).start(); countDownLatch.await(); }
-
To get test coverage, in addition to above follow below instructions.
-
Add maven-surefire-plugin to your pom.xml.
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.2</version> <configuration> <!-- <skipTests>true</skipTests> --> <systemPropertyVariables> <jacoco-agent.destfile>target/jacoco.exec </jacoco-agent.destfile> </systemPropertyVariables> </configuration> </plugin>
-
- Add Jacoco plugin to your pom.xml.
<plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.5</version> <executions> <execution> <id>prepare-agent</id> <goals> <goal>prepare-agent</goal> </goals> </execution> <execution> <id>report</id> <phase>prepare-package</phase> <goals> <goal>report</goal> </goals> </execution> <execution> <id>post-unit-test</id> <phase>test</phase> <goals> <goal>report</goal> </goals> <configuration> <!-- Sets the path to the file which contains the execution data. --> <dataFile>target/jacoco.exec</dataFile> <!-- Sets the output directory for the code coverage report. --> <outputDirectory>target/my-reports</outputDirectory> </configuration> </execution> </executions> </plugin>
- Add Jacoco plugin to your pom.xml.
- Run your tests using command :
mvn test.
-
-
- Set
-
There are 3 modes:
- Record: Sets to record mode.
- Test: Sets to test mode.
- Off: Turns off all the functionality provided by the API
Note: KEPLOY_MODE value is case sensitive.
We'd love to collaborate with you to make Keploy great. To get started: