InditexTech Karate Tools

Karate test module

The karatetools-oss-karate-test module.

This module karatetools-oss-karate-test is a karate module to test the karate tools.

  • This module has been generated using the ⚙️ Karate Tools - Archetype

  • Includes auto-generated tests and mocks for sample api (karatetools-oss-openapi-test)

  • uses the karatetools-oss-starter to test the karate clients and the sample application (karatetools-oss-boot) and containers.

Any changes made in the Karate Tools codebase must be reflected in the corresponding karate tests in this module.

The structure of the module is as follows:

  • src/test/java: Java Code

    e2e/karate/
    ├── .gitignore
    ├── pom.xml
    └── src
        └── test
            ├── java
            │   └── com
            │       └── inditextech
            │           └── karate
            │               └── karatetools
            │                   ├── jms
            │                   │   └── JMSKarateObject.java (1)
            │                   └── test
            │                       └── KarateRunnerTest.java (2)
    
    1 JMS Object for testing purposes
    2 Java Test Runner
  • src/test/resources: Base and Config files

    e2e/karate/
    ├── .gitignore
    ├── pom.xml
    └── src
        └── test
            └── resources
                ├── config (1)
                │   ├── db
                │   │   ├── mariadb-config-local.yml
                │   │   ├── mongodb-config-local.yml
                │   │   └── postgresql-config-local.yml
                │   ├── jms
                │   │   └── activemq-config-local.yml
                │   └── kafka
                │       ├── avro
                │       │   └── karate.avsc
                │       └── kafka-config-local.yml
                ├── config-local.yml (2)
                ├── config.yml (2)
                ├── jwt (3)
                │   ├── default-jwt.yml
                │   └── invalid-jwt.yml
                ├── karate-config.js (4)
                ├── logback-test-debug.xml (5)
                ├── logback-test.xml (5)
                └── mocks (6)
                    └── templates
                        └── standalone
                            └── .gitkeep
    1 Karate clients config files (db, jms, kafka)
    2 Configuration Files (general and environment specific)
    3 Karate Authentication JWT Files (default and test specific)
    4 Karate-config files
    5 logback configuration files
    6 karate mocks folder
  • src/test/resources/dev/inditex/karate: Tests related to Karate Tools features

    e2e/karate/
    ├── .gitignore
    ├── pom.xml
    └── src
        └── test
            └── resources
                ├── com
                │   └── inditextech
                │       └── karate
                │           ├── auth (1)
                │           │   ├── KarateAuthBackgroundScenario.feature
                │           │   ├── KarateAuthBasic.feature
                │           │   └── KarateAuthJWT.feature
                │           ├── base (2)
                │           │   └── KarateBase.feature
                │           ├── clients (3)
                │           │   ├── db (4)
                │           │   │   ├── JDBCClient-MariaDB.feature
                │           │   │   ├── JDBCClient-MariaDB.sql
                │           │   │   ├── JDBCClient-PostgreSQL.feature
                │           │   │   └── JDBCClient-PostgreSQL.sql
                │           │   ├── jms (5)
                │           │   │   └── JMSClient-ActiveMQ.feature
                │           │   ├── kafka (6)
                │           │   │   └── KafkaClients.feature
                │           │   └── mongodb (7)
                │           │       └── MongoDBClient.feature
    1 Authentication tests
    2 Karate Base tests
    3 Karate Clients tests
    4 Karate Clients tests: db
    5 Karate Clients tests: jms
    6 Karate Clients tests: kafka
    7 Karate Clients tests: mongodb
  • src/test/resources/apis/dev/inditex/karate/karatetools-openapi-test/xxx-api-rest-stable: Root folder for the operation(s) feature files and validation schemas for the test api xxx-api-rest-stable

    e2e/karate/
    ├── .gitignore
    ├── pom.xml
    └── src
        └── test
            └── resources
                ├── apis
                │   └── com
                │       └── inditextech
                │           └── karate
                │               └── karatetools-openapi-test
                │                   └── xxx-api-rest-stable (1)
                │                       └── BasicApi (2)
                │                           ├── createItems (3)
                │                           │   ├── createItems.feature (4)
                │                           │   └── schema (5)
                │                           │       ├── createItems_201.schema.yml
                │                           │       ├── createItems_400.schema.yml
                │                           │       ├── createItems_401.schema.yml
                │                           │       └── createItems_default.schema.yml
                │                           ├── listItems (3)
                │                           │   ├── listItems.feature (4)
                │                           │   └── schema (5)
                │                           │       ├── Items_200.schema.yml
                │                           │       ├── listItems_200.schema.yml
                │                           │       ├── listItems_400.schema.yml
                │                           │       ├── listItems_401.schema.yml
                │                           │       └── listItems_default.schema.yml
                │                           └── showItemById (3)
                │                               ├── schema (5)
                │                               │   ├── showItemById_200.schema.yml
                │                               │   ├── showItemById_401.schema.yml
                │                               │   ├── showItemById_404.schema.yml
                │                               │   └── showItemById_default.schema.yml
                │                               └── showItemById.feature (4)
    
    1 root folder for the operations
    2 api tag folder
    3 operation folder
    4 operation feature file
    5 operation validation schemas
  • src/test/resources/dev/inditex/karate/karatetools-openapi-test/xxx-api-rest-stable: REST Api tests

    e2e/karate/
    ├── .gitignore
    ├── pom.xml
    └── src
        └── test
            └── resources
                ├── com
                │   └── inditextech
                │       └── karate
                │           └── karatetools-openapi-test
                │               └── xxx-api-rest-stable (1)
                │                   ├── functional (2)
                │                   │   └── e2e (3)
                │                   │       ├── e2e.feature (4)
                │                   │       └── test-data (5)
                │                   │           ├── createItems_201.yml
                │                   │           ├── createItems_400.yml
                │                   │           ├── createItems_401.yml
                │                   │           ├── listItems_200.yml
                │                   │           ├── listItems_400.yml
                │                   │           ├── listItems_401.yml
                │                   │           ├── showItemById_200.yml
                │                   │           ├── showItemById_401.yml
                │                   │           └── showItemById_404.yml
                │                   └── smoke (6)
                │                       └── BasicApi (7)
                │                           ├── createItems (8)
                │                           │   ├── createItems.feature (4)
                │                           │   └── test-data (5)
                │                           │       ├── createItems_201.yml
                │                           │       ├── createItems_400.yml
                │                           │       └── createItems_401.yml
                │                           ├── listItems (8)
                │                           │   ├── listItems.feature (4)
                │                           │   └── test-data (5)
                │                           │       ├── listItems_200.yml
                │                           │       ├── listItems_400.yml
                │                           │       └── listItems_401.yml
                │                           └── showItemById (8)
                │                               ├── showItemById.feature (4)
                │                               └── test-data (5)
                │                                   ├── showItemById_200.yml
                │                                   ├── showItemById_401.yml
                │                                   └── showItemById_404.yml
    1 root folder for the rest api test
    2 root folder for the functional rest api tests
    3 specific functional test folder
    4 feature file
    5 test data files
    6 root folder for the smoke rest api tests
    7 api tag folder
    8 smoke tests operation folder

The tests to be executed are:

  • Karate Tests:

    • Karate tests are used to test the karate tools in the context of a Karate project.

    • These tests are executed against the test application Rest Api and the docker containers provided by the karatetools-oss-boot module.

Karate tests are required as status checks in the CI/CD pipeline pull request approval process. The level of coverage for the karate tests must reach at least the defined threshold.
Table 1. Tests Execution (Locally)
test command report verification

Build app

cd code

mvn clean install -DskipTests -DskipITs -DskipUTs

NA

no errors

Start app

cd code

APP_PORT=8888

PROJECT_VERSION=$(mvn -q -Dexec.executable="echo" -Dexec.args='${project.version}' --non-recursive exec:exec)

APP_PATH_TO_JAR=boot/target/karatetools-boot-$PROJECT_VERSION.jar

APP_OPTIONS=--server.port=$APP_PORT

java -jar "$APP_PATH_TO_JAR" "$APP_OPTIONS"

NA

no errors

karate

cd e2e/karate

APP_PORT=8888

mvn clean verify -DAPP_PORT=$APP_PORT -Dkarate.env=local -Dkarate.options="-t ~@mock.templates.inline -t ~@ignore" -Dkarate.report.options="--showLog true" -Dlogback.configurationFile=src/test/resources/logback-test-debug.xml

e2e/karate/target/karate-reports/karate-summary.html

all tests pass

Table 2. Tests Execution (Github)
test command report verification

karate

  • workflow dispatch

  • automatically on PR

workflow execution reports

automatically on workflow execution

Table 3. Tests Execution (Locally with Code Coverage)
step commands expected output

Build app

cd code

mvn clean install -DskipTests -DskipITs -DskipUTs

build without errors

Download JaCoCo agent and client

cd code

JACOCO_VERSION=$(mvn -q -Dexec.executable="echo" -Dexec.args='${jacoco.version}' --non-recursive exec:exec)

curl -k -s -S -L -o target/jacocoagent.jar https://repo1.maven.org/maven2/org/jacoco/org.jacoco.agent/$JACOCO_VERSION/org.jacoco.agent-$JACOCO_VERSION-runtime.jar

curl -k -s -S -L -o target/jacococli.jar https://repo1.maven.org/maven2/org/jacoco/org.jacoco.cli/$JACOCO_VERSION/org.jacoco.cli-$JACOCO_VERSION-nodeps.jar

ls -l target/jacoco*

JaCoCo agent and client downloaded

Start app with JaCoCo agent

cd code

APP_PORT=8888

PROJECT_VERSION=$(mvn -q -Dexec.executable="echo" -Dexec.args='${project.version}' --non-recursive exec:exec)

APP_PATH_TO_JAR=boot/target/karatetools-boot-$PROJECT_VERSION.jar

APP_OPTIONS=--server.port=$APP_PORT

JACOCO_AGENT_OPTIONS="-javaagent:target/jacocoagent.jar=dumponexit=true,output=file,destfile=target/jacoco-e2e/jacoco-e2e.exec,classdumpdir=target/jacoco-e2e/classes,excludes=SpringCGLIB:*HibernateProxy*:*MessagePostProcessor*:*Accessor*:*Instantiator*:.invoker.:*.*DTO,includes=dev.inditex."

java "$JACOCO_AGENT_OPTIONS" -jar "$APP_PATH_TO_JAR" "$APP_OPTIONS"

App started with JaCoCo agent

Wait for app to start

APP_PORT=8888

APP_HEALTH_PROBE=karatetools/health/docker

APP_HEALTH_CHECK_URL=http://localhost:$APP_PORT/$APP_HEALTH_PROBE

curl -s -o /dev/null -w \"%{http_code}\" $APP_HEALTH_CHECK_URL

Status code 200

Check docker containers are up

docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Image}}"

All docker containers are up in healthy state

Execute Karate tests

cd e2e/karate

APP_PORT=8888

mvn clean verify -DAPP_PORT=$APP_PORT -Dkarate.env=local -Dkarate.options="-t ~@mock.templates.inline -t ~@ignore" -Dkarate.report.options="--showLog true" -Dlogback.configurationFile=src/test/resources/logback-test-debug.xml

all tests pass

Check karate report

e2e/karate/target/karate-reports/karate-summary.html

all tests pass

Stop app

cd code

CTRL-C

App stopped

Generate JaCoCo report

cd code

JACOCO_CLI_REPORT_OPTIONS="target/jacoco-e2e/jacoco-e2e.exec --html target/jacoco-e2e --classfiles target/jacoco-e2e/classes --sourcefiles clients/src/main/java --sourcefiles generators/src/main/java --sourcefiles runner/src/main/java --sourcefiles boot/src/main/java"

java -jar target/jacococli.jar report $JACOCO_CLI_REPORT_OPTIONS

JaCoCo report generated

Check JaCoCo report

target/jacoco-e2e/index.html

code coverage generated by karate tests is at least 80%