Skip to content

Commit

Permalink
feat: add karate tests (#515)
Browse files Browse the repository at this point in the history
* chore: add karate structure

* feat: auto open karate report

* chore: open report even karate fail
  • Loading branch information
Thomgrus authored Oct 25, 2021
1 parent 9711eef commit 45771e9
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 0 deletions.
1 change: 1 addition & 0 deletions code/tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
secrets
47 changes: 47 additions & 0 deletions code/tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#####################################
## VARIABLES ##
#####################################

JAVA_VERSION=17

TARGET_ENV?=qualif

#####################################
## DEVELOP ##
#####################################

# Get ara tests secrets

secrets-import: ## Import secrets from GCP
@mkdir -p secrets
@gcloud secrets versions access latest --secret=karate-ara-qualif-config > secrets/karate-config-qualif.js

# WITH JAVA MAVEN

test-karate: ## Run tests. You can specify TARGET_ENV to change tests env.
@echo '-- Run tests With env: $(TARGET_ENV) --'
-@mvn test -DargLine="-Dkarate.env=$(TARGET_ENV) -Dkarate.config.dir=secrets"
@open file:///$$PWD/target/karate-reports/karate-summary.html


#####################################
## PACKAGE ##
#####################################


#####################################
## UTILS ##
#####################################

get-version: ## Get project version
@echo $$(xmllint --xpath '/*[local-name()="project"]/*[local-name()="version"]/text()' pom.xml)

update-version: ## Update project version. VERSION required
@mvn --batch-mode release:update-versions -DautoVersionSubmodules=true -DdevelopmentVersion=$(VERSION)-SNAPSHOT
@mvn --batch-mode versions:set -DremoveSnapshot -DprocessAllModules

.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.DEFAULT_GOAL := help
9 changes: 9 additions & 0 deletions code/tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# TESTS

This project is used to run test ARA.

It contains:

* Karate tests

Run `make` to display help.
45 changes: 45 additions & 0 deletions code/tests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?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>org.example</groupId>
<artifactId>tests</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-junit5</artifactId>
<version>1.1.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<testResources>
<testResource>
<directory>src/test/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>

</project>

13 changes: 13 additions & 0 deletions code/tests/src/test/java/TestParallel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import com.intuit.karate.Results;
import com.intuit.karate.Runner;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class TestParallel {
@Test
void testParallel() {
Results results = Runner.path("classpath:ara").tags("@sanity-check").parallel(1);
assertEquals(0, results.getFailCount(), results.getErrorMessages());
}
}
14 changes: 14 additions & 0 deletions code/tests/src/test/java/ara/login.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Feature: Connect to home page
Background:
* url authBaseUrl
* header Authorization = 'Basic ' + authToken
* form field grant_type = 'client_credentials'
* method post
* status 200
* def accessToken = response.access_token
@sanity-check
Scenario: Access Home Page
Given url araBaseUrl
And header Authorization = 'Bearer ' + accessToken
When method get
Then status 200
7 changes: 7 additions & 0 deletions code/tests/src/test/java/karate-base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function fn() {
karate.log('Karate config start reading...', karate.env); // get java system property 'karate.env'

// don't waste time waiting for a connection or if servers don't respond within 5 seconds
karate.configure('connectTimeout', 5000);
karate.configure('readTimeout', 5000);
}
24 changes: 24 additions & 0 deletions code/tests/src/test/java/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>target/karate.log</file>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<logger name="com.intuit.karate" level="DEBUG"/>

<root level="info">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>

</configuration>

0 comments on commit 45771e9

Please sign in to comment.