Groovy API Testing

I am writing a series of automated end-to-end test cases that use the RestFUL API.

I have some good test scripts written in Groovy that provide the types of tests and build the confidence we need, and we look at their integration into the nightly build, and also let the QA team run them. This is a step above unit testing because we are considering complete end-to-end work processes, not atomic steps.

Currently, the output is human-readable, with each test condition printing a line that defines the test, the value to be read, and the true / false value to indicate whether the test condition passes.

I would like to wrap this in a higher level script that calls each script individually and then analyzes the outputs. I can do this quite easily, but I was wondering if the Groovy Test framework exists there, so I am not reinventing the wheel.

+4
source share
2 answers

JUnit, TestNG, and Spock are all smart choices for writing (not just one) tests in Groovy. Choose one of them and run the tests using your build system. A build system such as Gradle , which can boot itself, will make QA's life easier (no installation required).

Disclaimer: I am the founder of Spock and the committer of Gradle.

+3
source

I use Groovy for this purpose. I just wrote JUnit 4 test cases in Groovy, and then I wrote my own custom Groovy runner script that collects the results and prints them out for me. This is the script for invoking JUnit 4 Groovy tests:

def (Result result, Duration duration) = time { JUnitCore.runClasses(TestA, TestB, TestC) } String message = "Ran: " + result.getRunCount() + ", Ignored: " + result.getIgnoreCount() + ", Failed: " + result.getFailureCount() println "" println "--------------------------------------------------" println "Tests completed after " + duration println "--------------------------------------------------" if (result.wasSuccessful()) { println "SUCCESS! " + message println "--------------------------------------------------" } else { println "FAILURE! " + message println "--------------------------------------------------" result.getFailures().each { println it.toString() } println "--------------------------------------------------" } def time(closure) { DateTime start = new DateTime() Object result = closure() [result, new Duration(start, new DateTime())] } 

I wrote this script because at that time I could not find the reusable JUnit 4 runner for Groovy. Now there may be one, but it works for me.

+1
source

All Articles