Running tests written by Diffblue Cover

Introduction

After Diffblue Cover has written tests for your project, they will be automatically integrated into your test suite. Before you can run the tests, you need to add any required dependencies for your particular build system.

Add the dependencies

Tests created by Diffblue Cover make use of the JUnit testing framework so JUnit is included in the required dependencies below. In some of the more complex cases, where mocking is required for example, it is necessary to include the additional (Mockito/Powermock) dependencies.

These dependencies are available from the Maven Central Repository. To use them, follow the guide relevant to your build tool - here we discuss Maven and Gradle.

Maven projects

To add the Diffblue Cover dependencies to your local Maven repository:

  1. Edit the root pom.xml.

  2. Add this dependency information to the <dependencies> section.

     <dependency>
       <groupId>org.powermock</groupId>
       <artifactId>powermock-api-mockito</artifactId>
       <version>1.6.5</version>
       <scope>test</scope>
     </dependency>
    
     <dependency>
       <groupId>org.powermock</groupId>
       <artifactId>powermock-module-junit4</artifactId>
       <version>1.6.5</version>
       <scope>test</scope>
     </dependency>
    
     <dependency>
       <groupId>org.mockito</groupId>
       <artifactId>mockito-all</artifactId>
       <version>1.10.19</version>
       <scope>test</scope>
     </dependency>
    
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>4.8.2</version>
       <scope>test</scope>
     </dependency>
    

Gradle projects

To add the Diffblue Cover dependencies to your local Gradle repository file:

  1. Edit the build.gradle file.

  2. Add Maven to the repositories section.

     repositories {
         mavenCentral()
     }
    
  3. Add JUnit and Mockito to the dependencies section:

     dependencies {
         testCompile group: 'junit', name: 'junit', version: '4.8.2'
         testCompile group: 'org.mockito', name: 'mockito-all', version: '1.10.19'
         testCompile group: 'org.powermock', name: 'powermock-api-mockito', version: '1.6.5'
         testCompile group: 'org.powermock', name: 'powermock-module-junit4', version: '1.6.5'
     }
    

Run the tests

Choose one of the new test classes in the project explorer, right-click and select 'Run ClassnameTest'.

The IDE will then show the results of the JUnit run.

results matching ""

    No results matching ""