title: how to reset value of groups of a Test method in TestNG when running the programme
body: <p>With two groups defined already:</p>
  
  <pre><code>public class GroupA {
  
      @BeforeGroups(groups = "groupA")
      public void beforeGroup1(){
          System.out.println("In before GroupA");
      }
  }
  
  public class GroupB {
  
      @BeforeGroups(groups = "groupB")
      public void beforeGroup1(){
          System.out.println("In beforeGroupB");
      }
  }
  </code></pre>
  
  <p>The test class is:</p>
  
  <pre><code>public class TestCls {
  
      @Test(groups="groupA")
      public void test(){
          System.out.println("In Test Class");
      }
  
  }
  </code></pre>
  
  <p>in the code of BeforeSuite, trying to reset the value of groups to "groupB" using the following code, it doesn't work as expected.</p>
  
  <pre><code>public class Suite {
  
      @BeforeSuite()
      public void test() throws NotFoundException {
          ClassPool pool = ClassPool.getDefault();      
          CtClass ct = pool.get(TestCls.class.getName());   
  
          //reset attribute groups from groupA to groupB 
          CtMethod ctMethod = ct.getDeclaredMethod("test");
          MethodInfo ctMethodInfo = ctMethod.getMethodInfo();
          ConstPool cp = ctMethodInfo.getConstPool(); 
  
          //reset attribute groups from groupA to groupB
          AnnotationsAttribute attribute = (AnnotationsAttribute)ctMethodInfo.getAttribute(AnnotationsAttribute.visibleTag);
          Annotation annotation = attribute.getAnnotation("org.testng.annotations.Test"); 
          ArrayMemberValue arrayMemberValue = new ArrayMemberValue(cp);
          StringMemberValue[] memberValues = new StringMemberValue[]{new StringMemberValue("groupB", cp)};
          arrayMemberValue.setValue(memberValues);
          annotation.addMemberValue("groups", arrayMemberValue);  
          attribute.setAnnotation(annotation);  
          ctMethodInfo.addAttribute(attribute);
  
          //check if groups changed successfully
          Annotation annotation2 = attribute.getAnnotation("org.testng.annotations.Test"); 
          MemberValue[] text = ((ArrayMemberValue)annotation2.getMemberValue("groups")).getValue();  
          System.out.println("the groups after modified is " + text[0]); 
      }
  }
  </code></pre>
  
  <p>the output is </p>
  
  <pre><code>the groups after modified is groupB
  In beforeGroup1
  In Test Class
  </code></pre>