samedi 29 janvier 2011

Do you know Spock ?

Spock is a very interesting testing framework. It integrates several
features like Mocking, a special testing language and it keeps
compatibility with xUnit.

Imagine you want test Energy of a beamline through a Control System

class Device{
  Device(def name){}
  static def energy=0
//private def gap
  def getGap(){-0.25*energy+11.5}
}

class EnergyProcess extends spock.lang.Specification {
  def beamline = new Device("I06-C-C00/EX/BeamlineEnergy")
  def undulator = new Device("ANS-C06/EI/C-U20")

  def "check the energy of my beamline"() {

     when: "a user change energy of beamline"
      beamline.energy = energy
     then: "the undulator should be in correct position"
      undulator.gap == gap

     where:
      energy | gap
          24 | 5.5
          22 | 6
          20 | 6.5
 }
}
I'm interesting in groovy language for few months (maybe years now) and
I think it would be a real candidate to create a testing environment for
Tango.

Aucun commentaire:

Enregistrer un commentaire