Creating a New TestProject OpenSDK Project

Before you can write tests with the TestProject OpenSDK, you have to choose the test automation framework, get the required dependencies, and figure out a way to build and run your tests.

This blog posts describes how you create a new TestProject OpenSDK project when you want to write your tests with Junit 5. After you have read this blog post, you:

  • Understand how you can install and configure the TestProject agent.
  • Know how you can get the TestProject developer key.
  • Can create a Maven project that gets the required dependencies and runs your tests.
  • Understand how you can create a Gradle project that gets the required dependencies and runs your tests.

Let’s begin.

This blog post is the second part of my TestProject OpenSDK tutorial that’s sponsored by TestProject.io. However, the views and opinions expressed in this tutorial are mine.

This blog post assumes that:

By the way, you might want to read the other parts of my TestProject OpenSDK tutorial.

Installing and Configuring the TestProject Agent

First, you have to create a new user account to the app.testproject.io website. You can create a new user account by opening the app.testproject.io website and clicking the ‘Sign up for free’ link found from the login dialog.

The following figure illustrates the location of the sign up link:

This blog post assumes that you logged in to the app.testproject.io website after you created your user account.

Second, you have to download the TestProject agent. You can get the TestProject agent by following these steps:

  1. Move your mouse pointer over the ‘Agents’ link found from the top menu.
  2. Choose the operating system and download the agent by clicking the correct download link.

The following figure illustrates the location of the download links:

Third, you have install the TestProject agent.

Fourth, you have to register your TestProject agent. You can do this by following these steps:

  1. Start your TestProject agent.
  2. Move your mouse pointer over the ‘Agents’ link found from the top menu.
  3. Click the ‘Register an agent link’ found from the opened menu. This opens a model dialog which allows you to register an agent.
  4. Enter the name of your TestProject agent and click the ‘Save’ link.
If your browser doesn’t allow popup windows, you have to either allow them or use a special registration url shown on your browser.

After you have registered your agent, you should see a page which states that your TestProject agent was registered successfully.

The following figure illustrates the location of the ‘Register an agent link’:

The following figure illustrates how you can enter the name of your TestProject agent:

Next, you will find out how you can get your TestProject developer key.

Getting the TestProject Developer Key

You can get the TestProject developer key by following these steps:

  1. Click the ‘Integrations’ link found from the top menu.
  2. Click the ‘Copy to clipboard’ icon found from the ‘Integrations’ page.

The following figure illustrates this process:

You will need your developer key in the next part of this tutorial which describes how you can configure the TestProject OpenSDK.

Let’s move on and find out how you can create a Maven project that gets the required dependencies, and compiles and runs your tests.

Creating a New Maven Project

When you want to create a Maven project that can compile and run tests which use both JUnit 5 and TestProject OpenSDK, you have to follow these steps:

First, you have to create a new Maven project.

Second, you have to ensure that your tests are run by the Maven Surefire plugin. You can do this by adding the following plugin declaration to the plugins section of your pom.xml file:

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

Third, you have to specify the required dependencies and add these dependencies to the test scope. You can do this by declaring these dependencies in your POM file:

  • The junit-jupiter-api (version 5.7.1) dependency provides the public API for writing tests and extensions.
  • The junit-jupiter-engine (version 5.7.1) dependency contains the implementation of the JUnit Jupiter test engine which runs your unit tests.
  • The java-sdk (version 0.65.4-RELEASE) contains the TestProject OpenSDK API. Because you are using JUnit 5, you must exclude the TestNG dependency. If you you don’t do this, the Maven Surefire plugin doesn’t recognize the test methods found from your test classes.

You can get the required dependencies by adding the following dependency declarations to the dependencies section of your POM file:

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <version>5.7.1</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-engine</artifactId>
    <version>5.7.1</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>io.testproject</groupId>
    <artifactId>java-sdk</artifactId>
    <version>0.65.4-RELEASE</version>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Next, you will learn to create a Gradle project that gets the required dependencies, and compiles and runs your tests.

Creating a New Gradle Project

When you want to create a Gradle project that can compile and run tests which use both JUnit 5 and TestProject OpenSDK, you have to follow these steps:

First, you have create a new Java project. After you have created this project, your build.gradle file looks as follows:

apply plugin: 'java'

sourceCompatibility = 15
targetCompatibility = 15

repositories {
    mavenCentral()
}

Second, you have to specify the required dependencies. You can do this by following these steps:

  1. Add the junit-jupiter-api (version 5.7.1) dependency to the testImplementation dependency configuration. This dependency provides the public API for writing tests and extensions.
  2. Add the junit-jupiter-engine (version 5.7.1) dependency to the testRuntime dependency configuration. This dependency contains the implementation of the JUnit Jupiter test engine which runs your unit tests.
  3. Add the java-sdk (version 0.65.4-RELEASE) dependency to the testImplementation dependency configuration. This dependency contains the TestProject OpenSDK API.

After you have declared the required dependencies, the source code of your build.gradle file looks as follows:

apply plugin: 'java'

sourceCompatibility = 15
targetCompatibility = 15

repositories {
    mavenCentral()
}

dependencies {
    testImplementation(
            'org.junit.jupiter:junit-jupiter-api:5.7.1',
            'io.testproject:java-sdk:0.65.4-RELEASE'
    )
    testRuntime(
            'org.junit.jupiter:junit-jupiter-engine:5.7.1'
    )
}

Third, you have enable the Gradle’s native JUnit 5 support. After you have done this, your build.gradle file looks as follows:

apply plugin: 'java'

sourceCompatibility = 15
targetCompatibility = 15

repositories {
    mavenCentral()
}

dependencies {
    testImplementation(
            'org.junit.jupiter:junit-jupiter-api:5.7.1',
            'io.testproject:java-sdk:0.65.4-RELEASE'
    )
    testRuntime(
            'org.junit.jupiter:junit-jupiter-engine:5.7.1'
    )
}

test {
    useJUnitPlatform()
}

You can now install and configure the TestProject agent, obtain your TestProject developer key, and build and run your tests by using Maven and Gradle. Let’s summarize what you learned from this blog post.

Summary

This blog post has taught you four things:

  • You can download the TestProject agent and get your developer key from the app.testproject.io website.
  • The TestProject OpenSDK dependency (java-sdk) contains the TestProject OpenSDK API.
  • If you are using Maven, you must exclude the TestNG dependency when you are declaring the TestProject OpenSDK dependency.
  • If you are using Gradle, you must enable the Gradle’s native JUnit 5 support.

P.S. You can get the example application of this blog post from Github.

0 comments… add one

Leave a Comment