spock unit-test-Schleifen in der then-Klausel

Ich habe einen test mit loops in der then-Klausel:

result.each {
  it.name.contains("foo")
  it.entity.subEntity == "bar"
}

for (String obj : result2) {
  obj.name.contains("foo")
  obj.entity.subEntity == "bar"
}

Neu erkannte ich, dass die Schleifen sind nicht wirklich getestet. Egal ob ich die foo oder bar oder sonst was, der test ist immer grün 🙂
Ich fand heraus, dass Schleifen geprüft werden müssen, anders, z.B. mit 'jeder'? Aber nur ändern die 'jeder' auf 'jeder' wirft Ausnahme:

result.every {
  it.name.contains("foo")
  it.entity.subEntity == "bar"
}

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Spec expression: 1: expecting '}', found '==' @ line 1, column 61.
   s("foo") it.entity.rootEntity == "bar" }

Wie soll ich richtig mit loops in meinem test? Ich bin mit spock 0.7-groovy-2.0

InformationsquelleAutor radio | 2013-03-05
Schreibe einen Kommentar