Cloudogu Logo

Hello, we are Cloudogu!

Experts in Software Lifecycle Management and process auto­mation, supporter of open source soft­ware and developer of the Cloudogu EcoSystem.

featured image Functional Testing with Gauge
01/17/2017 in Quality

Functional Testing with Gauge


Daniel Huchthausen
Daniel Huchthausen

IT Consultant


Table of Contents

Gauge is a lightweight behavior driven testing framework that allows you to automate end-to-end tests. In this post we will show an example of how to write a test framework with Gauge in Java code.

If you want to learn how to install and get started with Gauge, you should read this introductory post from our partner blog.

Gauge in General

With Gauge, test cases are written in two different layers: the human readable test specifications and the test execution, written in a programming language. This structure of the tests has two great advantages:

  • You create readable documentation by writing your test specification
  • Test specifications are written in Markdown – therefore non-programmers can write and design them. Programmers can than implement the test code using a programming language.

Beyond that, Gauge also comes with many alternatives for working with it:

  • To use Gauge you can either use the command line tool or with your IDE: Intelli J and Visual Studio are supported.
  • Depending on the situation and your personal preference you can write test cases in different languages. You can choose between C#, Java, Ruby and Groovy.
  • Test data can be provided via text- or CSV-files.
  • For the test execution you can choose between Maven, Ant and Gradle.

Example

To show you how writing tests with Gauge works, we want to show you an example for some tests that we wrote for the Cloudogu Ecosystem. In the left column you see the human readable test specifications written in Markdown and in the right column the test code written in Java.

Test Specification Test Code
SCM Integration Tests ===================== Tags: scm Some SCM integration tests
public class SCMSteps {
/*--------------
Authentication
--------------*/
Tags: scm, workflow Test SCM Cas Authentication Workflow
/*----------------------------
Scenario 1 Authentication
----------------------------*/
* Open SCM
  @Step("Open SCM")
    public void openSCM(){
      Driver.webDriver.get(EcoSystem.getUrl("/scm"));
      assertThat(Driver.webDriver.getTitle(),
      startsWith("CAS"));
    }
* SCM-Login "admin" with password "password"
  @Step("SCM-Login <user> with password <pwd> ")
  public void loginToCasSCM(String user, String pwd){
    assertThat(Driver.webDriver.getTitle(),
    startsWith("CAS"));
    CasPage page = EcoSystem.getPage(CasPage.class);
    page.login(user,pwd);
    SCMPage scmPage =   EcoSystem.getPage(SCMPage.class);
    assertThat(scmPage.getCurrentUsername(), is(user));
    assertThat(Driver.webDriver.getTitle(),
      containsString("SCM Manager"));
  }
* Logout of SCM
  @Step("Logout of SCM")
  public void logOutOfCas(){
    SCMPage page = EcoSystem.getPage(SCMPage.class);
    page.logout();
    openSCM();
  }
/*--------------
REST API u+p
--------------*/
Tags: scm, rest_api Test API by accessing json-file without Cas Authentication
/*-----------------------------------
Scenario 2 REST API u+p
-----------------------------------*/
* Access SCM API via REST client for "admin" with password "password"
  @Step("Access SCM API via REST client
  for <user> with password <password> ")
  public void createRESTClientForSCMAPI(String user, String password){
    SCMAPI api = new SCMAPI(user,password);
    DataStore scenarioStore = DataStoreFactory.getScenarioDataStore();
    scenarioStore.put("api", api);
    scenarioStore.put("user", user);
  }
* Obtain SCM json file
  @Step("Obtain SCM json file")
  public void compareJsonFile(){
    DataStore scenarioStore = DataStoreFactory.getScenarioDataStore();
    SCMAPI api = (SCMAPI) scenarioStore.get("api");
    String user = (String) scenarioStore.get("user");
    String userName = api.getFirstName();
    assertThat(userName, is(user));
  }
* Close SCM API REST client
  @Step("Close SCM API REST client")
  public void closeRestClient(){
    DataStore scenarioStore = DataStoreFactory.getScenarioDataStore();
    SCMAPI api = (SCMAPI) scenarioStore.get("api");
    api.close();
  }

I guess our two example scenarios don’‘t need a lot of explanation. Scenario 1 consists of three steps: call the application SCM-Manager, login with defined login credentials and logout from the application. Scenario 2 tests the REST API of SCM-Manager. I’m pretty sure that, by reading the test specification, you already figured that out. This shows how good the test specifications are suitable to serve as documentation of an application’s functionality.

If you are now interested in Gauge, go to the website and get started.

Conclusion

Our experiences with Gauge are good. It is a versatile and straightforward solution to create automated end-to-end tests. Test cases can be reused and automated easily and the test specifications written in Markdown are a great way to write test documentation.

With kind regards,

your Cloudogu Team