Run configurations

Run configurations allow you to configure the environment variables and system properties that are used when Cover Plugin creates tests. It also allows you to manually specify the method, class, package, or prefix for writing tests.

Dialog

The IntelliJ run configuration dialog for Diffblue Cover contains the following elements:

  • Name - Provide a useful name for the run configuration.

  • Store as project file - If selected, the run configuration will be stored as a project file.

  • Test creation target - Select All in package, Class, Method, or Prefixes from the drop down to set the scope of items you're writing tests for. Enter the target details as appropriate.

  • Write skeleton tests - If selected, Cover Plugin will write skeleton tests instead of creating complete tests. See Creating skeleton tests for more information.

  • Environment Variables - Provide a list of key/value pairs to set environment variables.

To display the dialog box, go to Run > Edit Configurations. If needed, click Add New Configuration (the + button) and select Diffblue Cover.

To access the system properties setting, click the Modify options button, and select Add VM Options. The VM option text box is added to the Run Configuration options - use this to add JVM system properties in the standard format, for example -Dkey1=value1.

Creating a run configuration

Automatic creation

When you write tests with Cover Plugin a run configuration is created for your selection. For example, suppose we have the sample below:

package com.example;

public class StringUtils {

  public static boolean isPalindrome(final String s) {
    for (int i = 0; i < s.length() / 2; i++) {
      char first = s.charAt(i);
      char second = s.charAt(s.length() - 1 - i);
      if (first != second) {
        return false;
      }
    }
    return true;
  }
}

If you write tests for the method, the run configuration that is created will look like the following (to display the dialog box, go to Run > Edit Configurations and select the appropriate configuration from the list):

You will notice there's a split between the class name and the method name, and that the method includes the signature of the method you've selected – this is the (Ljava/lang/String;)Z string after the colon.

Manual creation

To create a run configuration "manually", go to Run > Edit Configurations, click Add New Configuration (the + button) and select Diffblue Cover.

First select the scope, then use the Browse action on the class/package (and method, if appropriate) to make your selection. If you've selected the method scope, the signature will be populated for you.

Template

If you have a particularly large list of system properties or environment variables that you would like to use every time you use Cover Plugin to write tests, you can specify a template. (File > New Projects Setup > Run Configuration Templates > Diffblue Cover). The values you specify will be used for any future run configurations.

Prefixes

If required, you can specify what packages, classes, or methods you want to restrict these operations to, by specifying one or more prefixes in the run configuration.

Example: io.corebanking.Account


Package example

Specify a package entry point using the standard Java naming convention, plus an optional trailing dot.

Syntax: <path>[.]


Trailing dot: <path>.

Example: com.a.

Description: Write tests for all accessible methods within package <path> (in our example, com.a) and any sub-packages. For example, tests could be written for sub-packages com.a.B and com.a.b.C


No trailing dot: <path>

Example: com.a

Description: Write tests for all accessible methods within any package that begins with <path> (in our example, com.a) and any sub-packages. For example, tests could be written for com.a, com.apple, com.apricot, com.apricot.pip, etc.


Class example

Specify a class entry point using the standard Java naming convention, plus an optional trailing dot.

Syntax: <path>[.]


Trailing dot: <path>.

Example: io.diffblue.corebanking.account.Account.

Description: Write tests for all accessible methods within class <path> only - in our example, io.diffblue.corebanking.account.Account.


No trailing dot: <path>

Example: io.diffblue.corebanking.account.Account

Description: Write tests for all accessible methods within any class that begins with <path> - in our example, this could include ...Account and ...AccountException.


Method example

Specify a method entry point using the standard Java naming convention, plus an optional method descriptor.

Syntax: <path>:[<methodDescriptor>]

Example: io.diffblue.corebanking.account.Account.addToBalance:

Description: Write tests for the specified method. If the optional method descriptor is omitted, all parameter and return types will be included.

A method descriptor is a list of type descriptors that describe the parameter types and the return type of a method, in a single string. For more information on method descriptors, see section 2.1.4 of the ASM 4.0 A Java bytecode engineering library.

Last updated