Acceptance test with gauge and spring boot

Hi, in this article I will try to explain how to build an acceptance test with gauge and spring boot. Acceptance test is last step of Technology-related Testing in Test Pyramid.

In development lifecycle, tests should be considered as part of the software development process and as developers we have to be very careful to be test-oriented developers. We should implement all steps of test pyramid. We direct the behavior, implementation and output of a product with tests. Every code, every scenario starts with a test.

I will give other information in a short and summary form to quickly enter the subject.

Test pyramid:
As Martin Fowler says: “The Test Pyramid is a metaphor that tells us to group software tests into buckets of different granularity. It also gives an idea of how many tests we should have in each of these groups.” for more information: test pyramid

Acceptance test:
“Formal testing with respect to user needs, requirements, and business processes conducted to determine whether a system satisfies the acceptance criteria and to enable the user, customers or other authorized entity to determine whether to accept the system.” says ISTQB.
for more information: acceptance test

Gauge is a free and open source test automation framework that takes the pain out of acceptance testing.Easy to install and well documented. Simple, flexible and rich syntax based on Markdown, Consistent cross platform/language support for writing test code. Gauge supports many languages like java, go, javascript and other popular programming languages. Also gauge support some ides like intellij and VS Code.

Gauge has a very useful reporting tool. After running tests, gauge provide tests result as report. Default report tool is html format but you can extract result as xml and json.

Let’s start to build our first gauge project.

Note: this project built on macOS and intellij IDEA

Firstly, we should install gauge
install gauge: brew install gauge

Gauge Template: gauge template list is show us which type and with which languages we can use with gauge.
Gauge supports maven and gradle. we will continue with maven for spring boot integration. Maven template comes with java 7 and late gauge version. Will change as java 8/11 and update gauge version in pom.xml

gauge template: gauge init -t

create project: gauge init java_maven

Congratulations! you created your gauge project.

Now you are ready to write your specs.
when you create a gauge project it will come example tests and specifications.

We are ready to use gauge with maven. Now we can open our project with any java IDE.
Don’t forget to upgrade maven plugin version, gauge version and java version. For running gauge specs in ide console or terminal;

running specs: mvn test

Note: If you did not install maven on your computer (or dont want to), you should add .mvn, mvnw and mvnw.cmd to your project directory. After that you can run “mvn” command.

Everything is OK now, after running test we are ready to integrate with spring boot.
Why spring boot? With spring boot; We can take advantage of cloud features and we can use spring boot auto configuration like openfeign, kafka, redis etc.

Lets integrate with spring boot!

With integration spring boot, our pom.xml will be like this:

Application Class: Like any other spring boot applications we should annotate with @SpringBootApplication our app class.

Next step: RegisterIOC. In gauge, we should register ioc container for running specs. With this registration specifications will find their implementations in bean methods.

Now, we can mark as @Component our classes and we can prepare tests like use spring boot application.

Now Let’s examine gauge specifications, package structure and other packages.

We should have package structure like below.

Specifications: “A test specification (spec) is a detailed statement of what will be tested. In Gauge, these are written in a .spec file.” In default specifications are in specs folder. If you want to change folder, you should specify it in pom.xml gauge-maven-plugin plugin section.

Let’s look at the example specification file and explain specs on it.

Components of a specification:
Specification heading: “A specification must begin with a specification heading. A specification must contain only one specification heading.” Specification heading is runnable, if we want to run the specific specification we can run specification file or open it and run the specification heading.

Specification heading is written in the <H1> Markdown syntax in one of the following ways:

# Spec Heading
Spec Heading

Scenario: Scenarios define our test business workflow in a particular specification. A specification must contain at least one scenario. Scenarios also runnable, we can run just specific scenarios.

A scenario starts after a scenario heading or a scenario name. The scenario heading is written in Markdown <H2> syntax in one of the following ways:

## Scenario heading
Scenario heading
— — — — — — — —

Steps: Steps are defining which steps will be executing during the scenario. Steps binded implementation methods which has @Step annotation and @Step has to same name with step name. Each Specification could have steps and Each Scenarios has to at least one step.

Steps starts with star(*);

* The word “gauge” has “3” vowels.

And all steps can takes one or more parameters.

Tags: Tags are used to associate labels with specifications or scenarios. Tags help in searching or filtering specs or scenarios.

Before Specification: In implementation which methods annotated @BeforeSpec will run before specification. It finds via tags when annotated method will run or not.

Before Scenario: Same situation eligible for annotated methods @BeforeScenario like @BeforeSpec. @BeforeScenario works also with tags.

Before Step: This annotation is has same feature like Before implementation above.

DataStore: Datastore holds given key value pairs for spec or scenario lifecycle.


.gauge: in this folder, gauge has running test informations and screenshots.

env: in this folder, gauge has environments variables. you can customize for your developments environments as you wish.

log: all gauge project logs are collecting in this folder.

reports: After running tests gauge extracts reports about tests to in this folder.

specs: This folder contains project specifications. if you want to keep specifications you should define it in pom.xml

src: Src folder contains test implementation codes.

manifest.json: this file has information about which language will be use with gauge and it keeps gauge plugins.

Spec Example With Spring

In this example, we will run a scenario for github api,

Firstly we add a new property file under env/default folder which name is and add github api url.


Next step is a create Feign client. Our Feign client will be like below.
feign code:

Next step is write our own spec:

Our spec implementation will like:

Finally, we wrote our spec with spring and used feign. With different cases you can use Kafka, Redis, or Rabbitmq etc.

Let’s run the tests and see the result.
For running test open console and run: mvn test

As a conclusion, we learned what is gauge and how it works and then we integrated gauge with maven and spring boot.

project source code: gauge-demo

have fun..

Cloud Native Technologist