1

this is part of a teardown script, but it is giving me some trouble.

while ( n-- > 0 ) {
    testRunner.testCase.setPropertyValue( "ExpectedNo" + n, "")
}

n starts with value 5 and does reset ExpectedNo0 through ExpectedNo4 to blank as it is supposed to do, but afterwards it sets up 46 more property entries as follows ExpectedNo/ ExpectedNo. ExpectedNo, ....

I am not sure what to make of this as I am not very versed in groovy.. any help would be appreaciated!

Hoax
  • 1,004
  • 2
  • 15
  • 31
  • sure it's not a problem somewhere else in your code? – tim_yates Oct 19 '12 at 09:06
  • What I mean is, that loop stops fine – tim_yates Oct 19 '12 at 09:25
  • i only have 2 loops (setup, teardown) in 2 different steps. I can see it setting up ok, but the above teardown script does too much :) – Hoax Oct 19 '12 at 09:40
  • The loop works though... You could try a different way round, ie: `5.times { testRunner.testCase.setPropertyValue( "ExpectedNo$it", "" ) }` or `for( n=0 ; n < 5 ; n++ ) { testRunner.testCase.setPropertyValue( "ExpectedNo$n", "" ) }` but as I don't think the loop is to blame, my guess is you'll see the same result... – tim_yates Oct 19 '12 at 09:46
  • I set it to removeProperty, which works fine. Its not optimal but whatever works, right? thx for your time – Hoax Oct 19 '12 at 10:57

1 Answers1

5

To understand the source of your problem, take a look at ASCII table (link to a one). You'll see that before characters '0'-'5' there stands (in reverse order) '/', '.', '-', etc. Groovy interprets your n as character instead of integer variable. All you need is to convert n from String to Integer. See the next SO question how to do this: Groovy String to int.

Community
  • 1
  • 1
Artem Zankovich
  • 2,319
  • 20
  • 36