I am writing a Spock integration test for a function that takes a DTO, that has a lot of member variables. The functionality to test is that one user role is allowed to change some member variables, but if that user tries to change one of the other fields, it should fail.
I don't want to manually write a test for every single field, so I figured, I could be using a where:
table like so:
where:
fieldname | value | isAccepted
"fieldA" | "val" | true
"fieldB" | "val" | false
...
For that, I'd have to be able to set the fields by the name in a string. In Java I'd have to use reflection for that. In Python I could just use setattr(object, fieldname, value)
for that.
Since I writing the test in Groovy, is there something idiomatic for that?
Aucun commentaire:
Enregistrer un commentaire