weissj
10 years agoNew Contributor
float automatically cast to int in assert so precision cannot be verified
I have an API endpoint that returns JSON. One of the fields is a number with one digit to the right of the decimal point. We need to verify that the value is correct with the correct precision. ...
- 10 years ago
You may do a script assertions something like below
import net.sf.json.groovy.JsonSlurper def jsonText = '''{ "registerableInstances" : { "subjectCode" : "10", "subjectNumber" : "02", "percentContribution" : 15.0, "departmentCode" : "10", "sortKey" : "000.010.00.0000.0200.2.000", "primary" : false, "displayNumber" : "10.02" } }''' def jsonSlurper = new JsonSlurper() def ri= jsonSlurper.parseText(jsonText).registerableInstances def expectedContribution = 15.0 def actualContribution = ri.percentContribution assert expectedContribution == actualContribution, "Expected value does not matches"