I just discovered that VS Code supports TestNG tests with the Test Runner for Java plugin.
Normally I run all my tests with mvn verify, while also passing some arguments (e.g. -D). We have a TestNG.xml file that defines the suites we run, which have parameters.
When I try running an individual test in VS Code with the Test Runner plugin, the test fails because all of our tests require parameters, which are normally provided by the TestNG xml file.
Is there a way to run an individual test in VS Code and/or pass the parameters to an individual test?
Example XML:
<suite name="main-test-suite">
<test name="A test">
<parameter name="browser" value="firefox" />
<parameter name="anotherRequiredParam" value="a value here" />
<classes>
<class name="com.app.SpecificTest" />
</classes>
</test>
</suite>
Example test:
public class SpecificTest extends RootTest {
@Test(priority=1, description="Some test")
@Parameters({})
public void runTest() {
// Test code here
}
}
Root test:
public abstract class RootTest {
@BeforeClass
@Parameters({"browser", "anotherRequiredParam"})
public void setup(String browser, String anotherRequiredParam) {
// Test setup here
}
}
Edit: I was able to pass parameters-per-test via the VS Code workspace settings, by passing -Dbrowser=firefox -DanotherRequiredParam=paramher via the VMArgs json.
I would much rather pass an XML file, but this is a temporary solution, not an actual answer.