Create and Execute TestNG test from a Plugin

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.

9 comments
Comment actions Permalink

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

0
Comment actions Permalink

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

<depends>TestNG-J</depends>

build.gradle

intellij {
version '2018.1.1'
plugins 'TestNG-J:8.0'

}

I looked in the TestNG META-INF/plugin.xml and saw there was no <id>.  So I tried using the <name> with no success.

<idea-plugin>
<name>TestNG-J</name>
<description>TestNG Integration</description>
<version>8.0</version>
<vendor>Theory In Practice, JetBrains</vendor>

So I tried a few other things without success.  

What is the ID for the TestNG plugin?

0
Comment actions Permalink
 

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/

0
Comment actions Permalink

Thanks for the quick reply Alex.  The full path to my TestNG plugin is

/Applications/IntelliJ\ IDEA\ CE.app/Contents/plugins/testng/lib/testng-plugin.jar

a relative path like below allows it to build and Intellij to find TestNGConfiguration.

build.gradle

intellij {
version '2018.1.1'
plugins 'testng/lib/testng-plugin.jar:8.0'
}

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?

import com.theoryinpractice.testng.configuration.TestNGConfiguration;
final TestNGConfiguration testNGConfiguration = (TestNGConfiguration) runnerAndConfigurationSettings.getConfiguration();

 

0
Comment actions Permalink

> plugins 'testng/lib/testng-plugin.jar:8.0'

Where is 8.0 came from?;) it should be just ‘plugins = [‘testng’]’

0
Comment actions Permalink

I saw that in the documentation you linked and tried it as well. 

plugins ['testng']

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.

0
Comment actions Permalink

Please provide entire `./gradlew buildPlugin --info` output

0
Comment actions Permalink

I figured it out.  It did not like the [].  So this works

plugins 'testng'

Thanks for the help!

0
Comment actions Permalink

Ouch, I missed the absence of '=' in your code. Yes, it should be `plugin 'testng'` or `plugins = ['testng']`.

0

Please sign in to leave a comment.