&l
That's just because alert(#{test.i}); is evaluated when the commandButton is rendered. You can see the changed value by telling JSF to render the script again:
alert(#{test.i});
alert(#{testClass.i});