mardi 26 janvier 2016

Mock an object in unit testing

Hello I am new in groovy on Grails, maybe this question has already been answered.

I need to make a unit test in spock for a service. The service includes only one function which takes arguments domain objects and a class object which is placed on the src folder.

How can I mock the object from the class and instantiate it (giving input on its arguments- testObjectList) using mock in spock? I know that for the domain objects I use @Mock. However, I am searching how to mock object class, and give it as an input.

Example:

class QService{

  boolean testfun(TestObject testobject){
  if (testobject.testObjectList== null) return false
  return true  
  }
}

and the class TestObject is the following:

class TestObject {
  List<String> testObjectList
}

Aucun commentaire:

Enregistrer un commentaire