...
Now we want to repeat the same unit test but for multiple inputs. Spock offers a nice feature Data tables that allows to put input and expected output values in a text table:
Code Block | ||
---|---|---|
| ||
package MyLibrary import net.pricefx.tdd4c.TestRun import spock.lang.Specification class RoundingUtlsTest extends Specification { def LOGIC_DIR = "MyLibrary+2020-01-01" def ELEMENT_NAME = "RoundingUtls" def "base rounding"() { when: TestRun testRun = TestRun.builder() .buildElementTest(LOGIC_DIR, ELEMENT_NAME) and: Script script = testRun.getElementScript() then: script.round(price, dp) == rounded where: price | dp || rounded 10.449 | 0 || 10 10.678 | 0 || 11 2.15 | 0 || 2 2.95 | 0 || 3 3.00 | 0 || 3 0 | 0 || 0 null | 0 || null 10.47449 | 3 || 10.474 10.47678 | 3 || 10.477 2.125 | 3 || 2.125 3.000 | 3 || 3.000 0 | 3 || 0 null | 3 || null } } |
...