It depends on the test runner you are using - most of them provide a feature called Data Provider.
In JUnit, you would use TNG/junit-dataprovider:
@DataProvider
public static Object[][] urlDataProvider() {
return new Object[][] {
"google.com",
"facebook.com",
/* ... */
};
}
@Test
@UseDataProvider("urlDataProvider")
public void multipleURLs(String url) {
driver.get(url)
}
@DataProvider
public static Object[][] urlDataProvider() {
return new Object[][] {
"google.com",
"facebook.com",
/* ... */
};
}
@Test
@UseDataProvider("urlDataProvider")
public void multipleURLs(String url) {
driver.get(url)
}
TestNG has a similar feature. See this blog post.