tv1902
tv1902

Reputation: 231

Test Velocity Template

I do have a velocity template something like

<TABLE>
<TH>
  NAME
</TH>
<TR>
   $!{name}
</TR>

  .....other code......

#foreach( $!{grade} in $!{student.gradeList} )
    <tr>
        <td align="center">$!{grade.mathGrade}</td>
        <td align="center">$!{grade.scienceGrade}</td>
    </tr>
#end

below is my json file

{
  "name":"xyz",
     ...other variables....
}

So, now I want to test this, but I am getting error that Variable $student has not been set. I checked that $student is not defined anywhere else in template. I tried to give random string value for that something like "student":"XYZ" but then it gave error that String does not have property named gradeList. How to solve this?

Upvotes: 0

Views: 702

Answers (1)

tv1902
tv1902

Reputation: 231

I found the solution, where I added student as an object in my json file something like:

{
"name": "XYZ",
"student": {
    "gradeList": [
        {
            "mathGrade": "A"
        },
        {
            "scienceGrade": "B"
        }
    ]
}

}

Upvotes: 1

Related Questions