# Test framework dependencies

Tests created by Diffblue Cover make use of a testing framework, namely one of JUnit 4, JUnit Jupiter, or TestNG - these frameworks are included in the required dependencies below. These dependencies are available from the Maven Central Repository. To add it, follow the guide relevant to your build tool.

## Maven

Check whether or not the test framework dependencies are already in your Maven project. If not, follow the instructions below to add it:

1. Edit the `pom.xml`
2. Add the [surefire plugin](https://maven.apache.org/surefire/maven-surefire-plugin/index.html) to the `build plugins` section

```
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.5.4</version>
        </plugin>
    </plugins>
</build>
```

{% hint style="info" %}
With recent versions of surefire, it is not necessary to specify any `plugin dependencies` for the specific testing framework being used; surefire will detect the versions specified in the `project dependencies` section as specified below.&#x20;
{% endhint %}

{% hint style="info" %}
Explicitly specifying a testing framework in the `plugin dependencies` (e.g. to override the provider) can result in a reduced capability in the surefire plugin. In some cases, this can prevent Cover from grouping tests correctly which affects coverage calculations.
{% endhint %}

1. Add JUnit or TestNG to the `dependencies` section:

**For JUnit 4:**

```
<dependencies>
  [...]
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.13.2</version>
      <scope>test</scope>
    </dependency>
  [...]
</dependencies>
```

**For JUnit Jupiter 5:**

```
<dependencies>
    [...]
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.9.1</version>
        <scope>test</scope>
    </dependency>
    [...]
</dependencies>
```

**For TestNG:**

```
<dependencies>
  [...]
    <dependency>
      <groupId>org.testng</groupId>
      <artifactId>testng</artifactId>
      <version>6.9.8</version>
      <scope>test</scope>
    </dependency>
  [...]
</dependencies>
```

## Gradle

Check whether or not the test framework dependencies are already in your Gradle project. If not, follow the instructions below to add it:

1. Edit the build script (`build.gradle` or `build.gradle.kts`).
2. Add Maven to the `repositories` section.

   ```groovy
    repositories {
        mavenCentral()
    }
   ```
3. Add JUnit or TestNG to the `dependencies` section:

**For JUnit 4:**

{% tabs %}
{% tab title="GROOVY" %}

```groovy
 dependencies {
     testCompile group: 'junit', name: 'junit', version: '4.13.2'
 }
```

{% endtab %}

{% tab title="KOTLIN" %}

```kotlin
 dependencies {
     testCompile("junit:junit:4.13.2")
 }
```

{% endtab %}
{% endtabs %}

**For JUnit Jupiter 5:**

{% tabs %}
{% tab title="GROOVY" %}

```groovy
 dependencies {
     testCompile group: 'org.junit.jupiter', name: 'junit-jupiter', version: '5.8.0'
 }
```

{% endtab %}

{% tab title="KOTLIN" %}

```kotlin
 dependencies {
     testCompile("org.junit.jupiter:junit-jupiter:5.8.0")
 }
```

{% endtab %}
{% endtabs %}

**For TestNG:**

{% tabs %}
{% tab title="GROOVY" %}

```groovy
 dependencies {
     testCompile group: 'org.testng', name: 'testng', version: '7.8.0'
 }
```

{% endtab %}

{% tab title="KOTLIN" %}

```kotlin
 dependencies {
     testCompile("org.testng:testng:7.8.0")
 }
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
The versions specified are the latest at the time of writing. Please use the latest versions available for the best results
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cover-docs-preview.diffblue.com/features/cover-cli/project-configuration/test-framework-dependencies.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
