Create and Execute TestNG test from a Plugin Follow
I'm looking to create a plugin that will create a TestNG test configuration and execute an existing test with a small addition to its VM parameters, similar to the below. Unfortunately, TestNGConfiguration cannot be found. I would expect it to be located in com.intellij.execution.configuration or configurations, but it is not.
RunManager manager = RunManager.getInstance(e.getProject());
RunnerAndConfigurationSettings selectedConfiguration = manager.getSelectedConfiguration();
TestNGConfiguration configuration = (TestNGConfiguration) selectedConfiguration.getConfiguration();
configuration.setVMParameters("-ea");
The above code snippet was found here.
Is TestNGConfiguration no longer used?
Is there a better way to create a TestNG test programmatically?
Thanks in advance for any help you can provide.
Please sign in to leave a comment.
Please see `com.intellij.execution.JUnitPatcher#patchJavaParameters(com.intellij.openapi.module.Module, com.intellij.execution.configurations.JavaParameters)`. It's reused in JUnit and TestNG.
BTW The QName is com.theoryinpractice.testng.configuration.TestNGConfiguration
Anna
Thanks Anna!
I'm now trying to import the TestNG plugin into my project. I followed the wiki on including plugin dependencies but I'm seeing an error "Cannot find TestNG-J:8.0. My plugin.xml and build.gradle look like the below.
plugin.xml
build.gradle
I looked in the TestNG META-INF/plugin.xml and saw there was no <id>. So I tried using the <name> with no success.
So I tried a few other things without success.
What is the ID for the TestNG plugin?
TestNG-J was updated in 2007. Apparently, it's not what you need.
TestNG plugin is bundled one, you don't need an id for it,
you need a directory name instead. Please see the documentation: https://github.com/JetBrains/gradle-intellij-plugin/
Thanks for the quick reply Alex. The full path to my TestNG plugin is
a relative path like below allows it to build and Intellij to find TestNGConfiguration.
build.gradle
Of course it led me to another question. Intellij now recognizes TestNGConfiguration which is great but when I build gradle is complaining "error: package com.theoryinpractice.testng.configuration does not exist". Any suggestions?
> plugins 'testng/lib/testng-plugin.jar:8.0'
Where is 8.0 came from?;) it should be just ‘plugins = [‘testng’]’
I saw that in the documentation you linked and tried it as well.
Unfortunately I see the same exception, "error: package com.theoryinpractice.testng.configuration does not exist".
The 8.0 came from the original doc i found, it is the version of the plugin.
Please provide entire `./gradlew buildPlugin --info` output
I figured it out. It did not like the []. So this works
Thanks for the help!
Ouch, I missed the absence of '=' in your code. Yes, it should be `plugin 'testng'` or `plugins = ['testng']`.