In addition to Ant support, the Secure Testing Framework now has included Gradle support! In the latest release of the Secure Testing Framework, you will see that there is an example build.gradle and gradle.properties included in the repository. In the build.gradle the first thing I’d like to call attention to is the first line:
apply plugin: “java”
This line is included because it is a java project. With the java plugin in gradle, there are implicit source sets that are defined. Further down in the build.gradle, we define our own source set based on our repository structure:

sourceSets {
  test {
    java {
      srcDir 'test/'
    }
  }
}

This means that for the “test” task that we inherit from the java plugin, gradle will look in the ‘test/’ directory or whichever is defined in this block. For example, if your tests are located in ‘src/main/unit_test/’ then in your build.gradle, your source set block would look like this:

sourceSets {
  test {
    java {
      srcDir 'src/main/unit_test/'
    }
  }
}

By default, the test source set is defined as ‘src/main/test’.

The next thing that is of note in the build.gradle is the ‘dependencies’ block, here we define which dependencies we have and where to find the dependencies. In the example repository, we have the Secure Testing Framework jar in the ‘lib’ directory, so in the build.gradle:
testCompile files('lib/stf-1.4.0.jar')
It’s also important to note that this jar is defined as a testCompile dependency meaning it’ll only resolve this dependency when a test task is called.

In order to make your build script more dynamic, the following block uses the $suite variable to define your TestNG test suite. The full block can be seen here:

test{
  useTestNG{
    suites "$suite"
  }
}

If you want to set a default for this suite you can define the variable in gradle.properties, in the following way:
suite = sample.xml.

You are also able to overwrite this variable by passing the -P option from the command line. For example:
gradle build -Psuite=test.xml

The final thing is that you can still pass properties, such as “host”, to the STF by using the -D flags:
gradle build -Dhost=www.google.com

You can find more information on the Secure Test Framework in the following blogs:
SecureCI Testing Framework
New Testing Framework Release
Testing Web Services Using STF

Leave a comment

Your email address will not be published. Required fields are marked *

X