title: Converting from JUnit 4 to TestNG. How do I deal with a parameter?
body: <p>I am trying to convert my already bulging project from JUnit 4 to TestNG, in order to get some decent reports out of it.</p>
  
  <p>I have been following a tutorial at <a href="http://test-able.blogspot.co.uk/2016/10/how-to-convert-test-classes-from-junit-to-testng.html" rel="nofollow noreferrer">http://test-able.blogspot.co.uk/2016/10/how-to-convert-test-classes-from-junit-to-testng.html</a></p>
  
  <p>But I do not get this bit at all.</p>
  
  <p>In my existing code, I had the following:</p>
  
  <pre><code>import org.junit.runner.RunWith;
  import org.junit.runners.Parameterized;
  import org.junit.runners.Parameterized.Parameter;
  import org.junit.runners.Parameterized.Parameters;
  @RunWith(Parameterized.class)
  @Parameter
  public static String browserName;  
  
  @Parameters
  public static Collection&lt;Object[]&gt; data () { 
      Common.printLine();
  
      debug.print(thisClass + " set up browser parameters: " + global.variables.browsers);
  
      switch(global.variables.browsers) {
          case "all":
              Object[][] data = { {"firefox"}, {"chrome"}, {"edge"} };
              return Arrays.asList(data);   
          case "firefox":
              Object[][] data1 = { {"firefox"}};
              return Arrays.asList(data1); 
          case "chrome":
              Object[][] data2 = { {"chrome"}};
              return Arrays.asList(data2); 
          case "edge":
              Object[][] data3 = { {"edge"}}; 
              return Arrays.asList(data3); 
          default:
              Object[][] data4 =  { {"firefox"}};
              return Arrays.asList(data4); 
      }  
  } 
  </code></pre>
  
  <p>The replacement code for testNG looks fine for the Parameters bit:</p>
  
  <pre><code>    @DataProvider(name = "data")
  public static Collection&lt;Object[]&gt; data () { 
      Common.printLine();
  
      debug.print(thisClass + " set up browser parameters: " + global.variables.browsers);
  
      switch(global.variables.browsers) {
          case "all":
              Object[][] data = { {"firefox"}, {"chrome"}, {"edge"} };
              return Arrays.asList(data);   
          case "firefox":
              Object[][] data1 = { {"firefox"}};
              return Arrays.asList(data1); 
          case "chrome":
              Object[][] data2 = { {"chrome"}};
              return Arrays.asList(data2); 
          case "edge":
              Object[][] data3 = { {"edge"}}; 
              return Arrays.asList(data3); 
          default:
              Object[][] data4 =  { {"firefox"}};
              return Arrays.asList(data4); 
      }  
  } 
  </code></pre>
  
  <p>This is what is suggested as equivalent for parameter, but I don't understand how to apply it?</p>
  
  <pre><code>@Test(dataProvider="data")
  public void test2(String keyword) {
  
  } 
  </code></pre>
  
  <p>Can anyone explain how to adapt my parameter shown above, browserName?</p>
  
  <p>I think browserName previously held the output from the Collection object, so that when, for instance, the input parameter (global.variables.browsers) was set to 'all', the test would be performed for each of the browsers in order.
  (as shown here: <a href="http://test-able.blogspot.co.uk/2016/03/do-cross-browser-test-automation-like-a-pro-part2.html" rel="nofollow noreferrer">http://test-able.blogspot.co.uk/2016/03/do-cross-browser-test-automation-like-a-pro-part2.html</a>)</p>