Found multiple declarations of @bootstrapwith for test class

Explanation:

The error message “found multiple declarations of @bootstrapwith for test class” is indicating that there are multiple instances of the ‘@bootstrapwith’ declaration in the given ‘test’ class. This means that the ‘@bootstrapwith’ annotation has been used more than once in the class, which is not allowed.

Example:

Let’s assume we have a test class called ‘MyTestClass’ that is using the ‘@bootstrapwith’ annotation. However, this annotation has been mistakenly added twice in the class, causing the error. Below is an example:


  import org.testng.annotations.Test;
  import org.testng.annotations.BootstrapWith;
    
  @BootstrapWith(MyBootstrap.class)
  public class MyTestClass {
    
      @Test
      public void testCase1() {
          // Test case implementation here
      }
    
      @BootstrapWith(MyOtherBootstrap.class) // This is the duplicate declaration causing the error
      @Test
      public void testCase2() {
          // Test case implementation here
      }
  }
  

In the above example, we have mistakenly added the ‘@bootstrapwith’ annotation twice in the ‘MyTestClass’ class. The first declaration uses the ‘MyBootstrap’ class, which is correct. However, the second declaration uses the ‘MyOtherBootstrap’ class, which is causing the error.

To fix this issue, you need to remove the duplicate ‘@bootstrapwith’ declaration from the test class. After removing the duplicate, the corrected code would look like this:


  import org.testng.annotations.Test;
  import org.testng.annotations.BootstrapWith;
    
  @BootstrapWith(MyBootstrap.class)
  public class MyTestClass {
    
      @Test
      public void testCase1() {
          // Test case implementation here
      }
    
      @Test
      public void testCase2() {
          // Test case implementation here
      }
  }
  

After removing the duplicate declaration, the error should no longer occur, and the test class should run without any issues.

Similar post

Leave a comment