Forum Discussion

LeonardoS's avatar
Occasional Contributor
6 years ago

MongoDB as a data source for data driven testing

I want to use MongoDB as a data source for data-driven testing. I'm able to connect to MongoDB via Groovy Scripts and I'm able to retrieve data. But I'm trying to figure out how to use that data as a...
  • JHunt's avatar
    6 years ago

    So you already have the data and just want to iterate over it? This is a common thing to want to do.


    Add the WSDL or REST resource to your project, and create a Request in the interface definition, and set up the request as a kind of template for the requests you will make in your test. You don't need any TestRequests in your TestCase, just a groovy script.


    This code shows how to iterate over your data and make basic assertions against the response.


    myRequest = testRunner
     .getRequestByName('Request 1')
    assert myRequest.requestContent == '''<soapenv:Envelope xmlns:soapenv="" xmlns:sam="">
    testData = [ [in: "A", out: "D"],[in: "B", out: "E"],[in: "C", out: "F"] ]
    testData.each { test ->
         context.myVariable =
          .submit(context, false)
          .with { 
          	if (it.contentAsString.contains(test.out)) {
  "Response for input of ${} contains ${test.out}")
          	} else {
          		log.error("Response for input of ${} did not contain ${test.out}")

    Notice how the test data for each run is added into the context, and then the context is passed into the call to submit.