mercredi 2 décembre 2015

How can I setup test data for functional testing in Grails?

So we have a restful service that we want to test using a restclient in grails.

The test code should go something like this...

class MyControllerSpec extends Specification {

def setup() {
  this.dbEntity = new DbEntity("someid123").save();
}

void "Test entity GET"{
        given:
            RestBuilder rest = new RestBuilder()

        when: "The DB entity service is hit"
            RestResponse restResponse = rest.post("http://localhost:8080/api/someentity/$id");

        then: "A 200 error is sent"
            restResponse.status == 200


}

The problem I am having is the setup method blows up on .save() because there is not hibernate session. How can I manipulate my database before running a test?

Aucun commentaire:

Enregistrer un commentaire