-
Notifications
You must be signed in to change notification settings - Fork 15
Add Karate integration example with Testomat.io support #104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
- Introduced a new Karate project with a Maven setup, including a `pom.xml` for dependencies. - Added a README.md detailing setup instructions, test scenarios, and integration steps. - Created feature files for testing the Swagger Petstore API with unique test IDs. - Implemented a test runner in Java to execute the Karate tests and generate JUnit XML reports.
DavertMik
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To verbose overview
|
|
||
| # 3. Create pom.xml with Karate dependencies | ||
| cat > pom.xml << 'EOF' | ||
| <?xml version="1.0" encoding="UTF-8"?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need to do things like that?
YevheniiVlasenko
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job! There are a few things to improve!
| { | ||
| "permissions": { | ||
| "allow": [ | ||
| "mcp__context7__resolve-library-id", | ||
| "mcp__context7__get-library-docs", | ||
| "Bash(mkdir:*)" | ||
| ], | ||
| "deny": [], | ||
| "ask": [] | ||
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this does not belong here. It's local.
|
|
||
| ``` | ||
| karate-example/ | ||
| ├── pom.xml | ||
| ├── README.md | ||
| └── src/ | ||
| └── test/ | ||
| ├── java/ | ||
| │ └── com/ | ||
| │ └── testomat/ | ||
| │ └── karate/ | ||
| │ └── KarateTest.java | ||
| └── resources/ | ||
| └── simple-api-test.feature | ||
| ``` | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this structure refers to the project the user creates in the first part of the README, then it's wrong. If it does not then as a user I can't see where I get this from.
| ## 🚀 Setup Framework From Scratch (In a Nutshell) | ||
|
|
||
| ### Quick Setup (5 minutes) | ||
|
|
||
| ```bash | ||
| # 1. Create project directory | ||
| mkdir my-karate-project | ||
| cd my-karate-project | ||
|
|
||
| # 2. Create Maven directory structure | ||
| mkdir -p src/test/java/com/example/karate | ||
| mkdir -p src/test/resources | ||
|
|
||
| # 3. Create pom.xml with Karate dependencies | ||
| cat > pom.xml << 'EOF' | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 | ||
| http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <groupId>com.example</groupId> | ||
| <artifactId>karate-project</artifactId> | ||
| <version>1.0.0</version> | ||
| <properties> | ||
| <maven.compiler.source>11</maven.compiler.source> | ||
| <maven.compiler.target>11</maven.compiler.target> | ||
| <karate.version>1.4.1</karate.version> | ||
| </properties> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>com.intuit.karate</groupId> | ||
| <artifactId>karate-junit5</artifactId> | ||
| <version>${karate.version}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| <build> | ||
| <testResources> | ||
| <testResource> | ||
| <directory>src/test/java</directory> | ||
| <excludes><exclude>**/*.java</exclude></excludes> | ||
| </testResource> | ||
| </testResources> | ||
| </build> | ||
| </project> | ||
| EOF | ||
|
|
||
| # 4. Create test runner | ||
| cat > src/test/java/com/example/karate/TestRunner.java << 'EOF' | ||
| package com.example.karate; | ||
| import com.intuit.karate.Results; | ||
| import com.intuit.karate.Runner; | ||
| import org.junit.jupiter.api.Test; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| public class TestRunner { | ||
| @Test | ||
| void testAll() { | ||
| Results results = Runner.path("classpath:") | ||
| .outputJunitXml(true) | ||
| .parallel(1); | ||
| assertTrue(results.getFailCount() == 0, results.getErrorMessages()); | ||
| } | ||
| } | ||
| EOF | ||
|
|
||
| # 5. Create your first .feature file | ||
| cat > src/test/resources/sample-test.feature << 'EOF' | ||
| Feature: Sample API Test | ||
|
|
||
| Background: | ||
| * url 'https://petstore.swagger.io/v2' | ||
|
|
||
| Scenario Outline: Get pet - <testCase> @<testId> | ||
| Given path 'pet', <petId> | ||
| When method get | ||
| Then status <expectedStatus> | ||
|
|
||
| Examples: | ||
| | testCase | petId | expectedStatus | testId | | ||
| | existing | 1 | 200 | T1a2b3c4d | | ||
| | nonexistent | 999 | 404 | T5e6f7g8h | | ||
| EOF | ||
|
|
||
| # 6. Run your first test | ||
| mvn test | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As it's a demo project that will not be or will be rarely updated, I would rather do this using Maven Archetype or, simpler, tell the user to clone the project with a ready-to-use structure. Both ways are more user-friendly and faster to use.
pom.xmlfor dependencies.