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

In ordinary Java code, the quotation marks in @Optional("mysql") are string-literal delimiters; they are not part of the value. If a TestNG method actually receives quote characters, they came from the value supplied to the method—often an escaped quote in Java, an " entity in testng.xml, or a command-line or system-property argument. Trace the value to its source, then remove quotes that are data while keeping the syntax required by Java, XML, or your shell.

What @Optional does—and what its quotes mean

TestNG’s @Optional annotation supplies a default for a method parameter when the matching parameter is absent. For example:

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

public class DatabaseTest {
    @Test
    @Parameters("db")
    public void connectsToDatabase(@Optional("mysql") String db) {
        System.out.println("[" + db + "]");
    }
}

If no matching db parameter is supplied, the default value is mysql. The double quotes in the Java source mark the beginning and end of a string literal. Java does not pass those delimiters as part of the string. TestNG’s parameter documentation uses this same example: if db is absent from testng.xml, the method receives the default mysql.

So if the output is [mysql], the quotes in the annotation are behaving normally. If it is ["mysql"], the square brackets are just a way to show the boundaries: the value itself contains quote characters. The fix depends on which source supplied that value; changing the annotation alone may have no effect if XML or a system property overrides its default.

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

First, confirm whether the quotes are really in the value

Make invisible boundaries visible at the method that receives the parameter. This temporary diagnostic prints the value between brackets and reports each character as a Unicode code point:

System.out.println("db = [" + db + "]");
System.out.println("db length = " + db.length());
db.codePoints().forEach(cp ->
    System.out.printf("U+%04X ", cp));
System.out.println();

For mysql, the displayed value should be [mysql], with six code points: U+006D U+0079 U+0073 U+0071 U+006C. If quote characters are part of the value, the output includes U+0022 at the beginning and end. This distinguishes actual double quotes from quotes that a log formatter or debugger may add when displaying a string.

Keep the diagnostic close to the receiving method. Checking a value in a different class, or only inspecting the annotation, does not establish what TestNG passed after resolving the available parameter sources.

Trace the source that supplied the parameter

TestNG parameters can come from XML, system properties, or programmatic sources. The annotation default is only one possible source. Find the parameter that was actually matched before editing anything.

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

Check the annotation default

For the plain value mysql, write:

@Optional("mysql")

Do not escape quote characters into the literal unless you intend them to be part of the data. In Java source, an escaped double quote is written as " inside the string literal, for example:

@Optional(""mysql"")

That deliberately creates the value "mysql", including the quote characters. If those characters are not wanted, remove the escapes and leave the ordinary string delimiters in place.

Check the matching testng.xml value

XML requires quotes around an attribute value, but those boundary quotes are syntax, not data. This supplies the value mysql:

<parameter name="db" value="mysql"/>

By contrast, &quot; encodes a literal double quote within an XML attribute. This supplies quote characters around the word:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
What's New in Java 7
  • Made of PP material, health and environmental protection
  • Stack, save storage space, with grid, storage can be classified.
  • Higher edge, can be stacked to save space.
  • Durable
<parameter name="db" value="&quot;mysql&quot;"/>

If the receiving method gets quoted text unexpectedly, remove the entities around the value:

<parameter name="db" value="mysql"/>

Do not remove the XML attribute’s own delimiting quotes. XML 1.0 defines &quot; as the character reference for a double quote; ordinary attribute delimiters simply mark where the attribute value begins and ends.

Check parameter names, scopes, and method order

A correct default will not help if a matching parameter elsewhere supplies a different value. TestNG documents parameters at suite, test, class, and method scope, with more specific scopes taking precedence in this order:

<suite> --> <test> --> <class> --> <methods>

Inspect the applicable XML scope for the exact parameter name. Also check the name in @Parameters and the method signature: TestNG maps the XML parameter names to Java parameters in the order listed in the annotation. A nearby parameter with a similar name is not necessarily the one being injected.

Free tools Windows power users keep installed

One-click scans. No signup required.

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

For example, this method requests db; a setting named database is not the same name:

@Parameters("db")
public void connectsToDatabase(@Optional("mysql") String db) {
    // ...
}

Check system properties and the runner command

TestNG also documents system properties as a parameter source. If your project passes the value through a JVM option such as -Ddb=..., inspect the effective property and the exact command produced by your build tool or test runner. Quoting rules differ between shells and build configurations: quotes may group a value containing spaces, or they may be passed through as characters, depending on how the command is constructed. The command line shown by one shell is not proof of the argument the JVM ultimately receives.

TestNG’s documentation illustrates a spaced system-property value with java -Dlast-name="von Braun" .... That example shows why quotes may be needed in a command, but it does not establish how every shell or build tool parses a particular invocation. Check the argument delivered to the JVM, then remove quote characters only if they are present as data and are not intended.

Fix the source, not the visible symptom

  1. Print the received value with boundaries. Use brackets and, if needed, code points to verify whether U+0022 characters are present.
  2. Identify the active source. Check the annotation default, matching XML parameter, JVM property, or programmatic configuration. Do not assume the default was used just because the method has @Optional.
  3. Remove only unwanted data quotes. In Java, remove escaped quotes from the string value; in XML, remove &quot; around the text; in a command or build configuration, correct the argument after considering its parser.
  4. Keep required syntax. Retain Java string delimiters, XML attribute delimiters, and any shell quoting needed to preserve a value with spaces.
  5. Run the test again and inspect the receiving method. Verify the actual value after TestNG resolves the parameter rather than relying on a source-file appearance.

If a quote is genuinely part of the intended input—for instance, the database setting itself is supposed to include quote marks—do not strip it just to make the display look cleaner. The right value is determined by the consumer’s contract. This debugging procedure is for the case where the method receives quotes unintentionally.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common symptoms and what to check

Observed result Likely place to inspect Correction
The source says @Optional("mysql"), and the method receives mysql. No problem is indicated by the ordinary Java quotes. No change is needed; the delimiters are not part of the string.
The method receives "mysql" as text. An escaped quote in a Java string, XML &quot;, or an argument that includes quote characters. Remove the quote characters at the source that supplied the value, unless they are intentional data.
You changed @Optional, but the method still receives the old value. A matching parameter supplied from XML or another source; check applicable scopes and property configuration. Edit the active source, not an unused default.
The method receives an unexpected value with no quote characters. Parameter name, XML scope, annotation ordering, or a different parameter source. Trace the exact named parameter and the value TestNG resolves for the method.
The display looks quoted, but the character check finds no U+0022. The debugger or logging representation rather than the parameter value. Use the raw value or character output to decide whether a fix is necessary.

Version and diagnostic limits

The behavior described here follows TestNG’s parameter documentation. The API reference cited for @Optional is specifically for TestNG 7.9.0 and describes the annotation as specifying a default, or null when no default is set. The general parameter behavior discussed above is not limited here to a particular installed TestNG version. If your result differs, check the documentation for the version actually in use and inspect the resolved value in your run; without the test source, XML, runner command, and version, no single cause can be assigned to an individual failure.

Or skip the browser setup

ScreenshotNeo does not change TestNG parameter injection or remove quote characters from a Java string. It is a separate option when you also need a website screenshot—for example, to capture how a test page renders. Its one-request API returns a screenshot or PDF, and its screenshot options include custom headers, cookies, JavaScript, and waiting for a selector or network idle. The API accepts parameters used by other screenshot APIs to make switching easier.

For a screenshot of the TestNG documentation page, for example, adapt the target URL in this cURL call. The ScreenshotNeo API documentation describes the available parameters.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://testng.org/ -o shot.webp
  • It accepts cookie or consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off.
  • Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing. Each response reports the page verdict and billing status in X-Page-Verdict and X-Billed headers.
  • An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.
  • The Free plan includes 1,000 shots per month with no card. Paid plans start at $5 for 3,000 shots; yearly billing gives two months free, and every feature is available on every plan.

Learn about ScreenshotNeo or sign up for 1,000 free screenshots a month with no card.

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

Quick Recap

Bestseller No. 3
What's New in Java 7
What's New in Java 7
Made of PP material, health and environmental protection; Stack, save storage space, with grid, storage can be classified.

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.