How to use TestNG in Gradle project

A statement: IntelliJ IDEA likes JUnit. Thing is, it’s gonna try to use JUnit even if you create a test with TestNG selected in settings. When you are ready to run your tests, you are probably about to encounter the following error: Test filtering is not supported for given version of JUnit. Please upgrade JUnit version to at least 4.6. Here is what needs to be done in this case:

  1. (optional) Add TestNG as Gradle dependency. At this moment you probably have it added by pressing ‘Fix’ button in ‘Create test’ dialog window. This is not a required step, I just prefer to have all the dependencies in one place.
  2. Explicitly tell Gradle to use TestNG as a testing framework.

Here’s how the modified build.gradle will look like:

apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
testCompile 'org.testng:testng:6.9.4'
}
test {
useTestNG()
}

Advertisements

Published by

Victor Lapin

Head of a Software Development Group

One thought on “How to use TestNG in Gradle project”

Add a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s