Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use TestNG’s XML @Parameters for a small set of named run settings, such as an environment or browser; use @DataProvider to run the same test method with multiple sets of test-case data. XML values map to method arguments by the names in @Parameters, while provider rows map positionally to the test method’s arguments.

Choose XML parameters or a DataProvider

Question XML @Parameters @DataProvider
Best for A few named values that configure a run, such as an environment or browser A series of cases that exercise the same test logic
Where values are defined In testng.xml, at suite, test, class, or method scope In a Java provider method or generated by that method
How values map Parameter names in @Parameters match XML names; argument order follows the annotation Each returned row supplies the test method’s arguments in order
Parallel option Not the data-provider parallel mechanism Opt in with parallel=true; pool settings depend on TestNG version

These mechanisms solve different problems. A browser selection is usually configuration, not a test case. A list of username/password combinations is test data, not a set of unrelated run settings. TestNG’s parameter documentation describes XML parameters and their scopes.

Pass a named setting from testng.xml

In this example, the suite declares an environment value, and the test method requests that name. The optional annotation supplies staging only if no value is supplied through XML or another supported parameter source.

Java test class

package example;

import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class EnvironmentTest {
  @Test
  @Parameters("environment")
  public void usesConfiguredEnvironment(
      @Optional("staging") String environment) {
    System.out.println("Environment: " + environment);
    // Assert behavior for the selected environment.
  }
}

Suite XML

<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Environment suite">
  <parameter name="environment" value="qa"/>
  <test name="Environment checks">
    <classes>
      <class name="example.EnvironmentTest"/>
    </classes>
  </test>
</suite>

Place the XML file where your TestNG runner expects it and run the suite with your project’s existing TestNG setup. With the shown XML value, the method receives qa. The code is illustrative; it assumes TestNG is already included in the project and does not prescribe a build tool or dependency version.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Names, ordering, and scope

  • The name in @Parameters must match the XML parameter name. With multiple names, list them in the same order as the method arguments, for example @Parameters({"environment", "browser"}) for method(String environment, String browser).
  • TestNG supports declarations at suite, test, class, and method scope. A more specific declaration takes precedence over a broader declaration with the same name; a method-level value can therefore override a suite-level value.
  • @Optional provides a fallback when the XML parameter is absent. It does not correct a misspelled parameter name or an argument mismatch.
  • JVM system properties can override values declared in testng.xml, which is useful for changing configuration from a command line without editing the suite file. Consult the official parameter documentation for the mechanism and behavior applicable to your TestNG version.

Run multiple cases with a DataProvider

A provider returns rows, and TestNG invokes the test method once per row. In the example, each inner array contains the username and password for one invocation.

package example;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class LoginTest {
  @DataProvider(name = "credentials")
  public Object[][] credentials() {
    return new Object[][] {
      {"reader", "correct-password"},
      {"locked-user", "any-password"}
    };
  }

  @Test(dataProvider = "credentials")
  public void loginCases(String username, String password) {
    // Exercise the login behavior for this row.
  }
}

The provider name referenced in @Test(dataProvider = "credentials") must match the provider’s declared name. If no name is declared, the provider method’s name is used by default. The row’s first value becomes username and its second becomes password; a different row shape or ordering will not be converted into named arguments for you.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Return shapes and generated cases

The TestNG 7.9.0 API documents Object[][] and Iterator<Object[]> for multiple-argument cases, and Object[] and Iterator<Object> for a single argument. An iterator can be useful when cases are generated lazily rather than assembled as one array. See the TestNG 7.9.0 DataProvider API and check the API for the version your build uses.

Enable and configure parallel provider runs

Data-provider execution is not parallel by default. Add parallel = true to the annotation when concurrent invocations are appropriate:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
@DataProvider(name = "credentials", parallel = true)
public Object[][] credentials() {
  return new Object[][] {
    {"reader", "correct-password"},
    {"locked-user", "any-password"}
  };
}

TestNG documents a default pool size of 10 for parallel data providers invoked from XML; the suite’s data-provider-thread-count can adjust the size. These are framework settings, not a guarantee that a test is safe to run concurrently. Keep cases independent where possible, and avoid sharing mutable state unless it is deliberately synchronized or isolated.

From TestNG 7.9.0, suite-level share-thread-pool-for-data-providers and use-global-thread-pool controls are available. The 7.9.0 documentation directs users to the testng-1.1.dtd for these attributes. Confirm version support and the relevant XML DTD before adding them; do not assume a setting documented for 7.9.0 exists in an older build. The official TestNG documentation and the TestNG 7.11.0 DataProvider API are useful references for version-specific behavior.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot parameterization errors

  • Parameter not found or unresolved: Check that the XML name exactly matches the string in @Parameters, and that the XML file being run contains the declaration.
  • Unexpected parameter value: Check declarations at suite, test, class, and method scope. A narrower scope may override a broader value; also check whether a JVM system property is overriding XML.
  • Method arguments do not match: For XML, ensure the annotation names and method arguments correspond in count and order. For a provider, verify every row has the right number of values and that each position has a compatible type.
  • Data provider cannot be resolved: Verify the name in @Test(dataProvider = ...) matches the provider name, or use the provider method’s name when relying on the default.
  • Provider returns unsupported data shape: Use a documented return form for the argument count: for example, Object[][] or Iterator<Object[]> for multiple arguments.
  • Parallel cases fail intermittently: Look for shared mutable test data, files, browser sessions, or other state used by concurrent invocations. Disable parallel execution while isolating the issue, then make cases independent before enabling it again.
  • New XML attributes are rejected: Check the TestNG version and DTD. The shared/global provider pool controls are documented from 7.9.0, with the newer DTD noted for those attributes.

Or skip the browser setup

For a website screenshot rather than a TestNG test run, ScreenshotNeo offers a single GET request that returns an image or PDF. Its clean-shot options accept consent banners and remove more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for AI agents.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for output formats and request options. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Sign up for ScreenshotNeo to start with the free plan. ScreenshotNeo is a Yorker Media product; learn more at screenshotneo.com.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Frequently Asked Questions

Can I use XML parameters and a DataProvider in the same TestNG project?

Yes. Use XML parameters for named run configuration and a DataProvider for case rows; choose the mechanism that matches each value’s role.

Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Does a DataProvider run each row concurrently automatically?

No. Parallel execution must be enabled on the provider with parallel = true.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.