How to make groovy Syntax in spock
This article is to share with you about how to make groovy grammar in spock. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
Introduction
When using the spock test framework, the following test code often appears:
/ / Test method def "test plus 1" () {given: "prepare data" def a = 1 def b = 2 when: "Test method" def c = calculateService.plus (a, b) then: "check result" c = = 4-1}
Many people treat it as a fixed format, especially those like me who started groovy and spock from java in a few days, and hardly delve into what grammar this is.
In fact, some groovy-specific syntax formats are used in the spock framework, which are not common in Java, as follows:
Labeled statements label statement
Any statement can be associated with a label. Labels do not impact the semantics of the code and can be used to make the code easier to read like in the following example:
Any statement can be associated with a tag, which not only does not change the semantics, but also makes the statement more readable, as follows:
Given: def x = 1 def y = 2when: def z = x+ythen: assert z = = 3
In fact, there is also a tag statement in java, with the following code:
For (int iTuno Bandi)