This topic explains how to set up and run a pre-commit code review process where developers submit code for review before it is committed to source control. Each time a developer needs their code reviewed, he or she runs the Code Review Test Configuration. This Test Configuration detects code changes and prepares them for review. 

Section include:

Configuration Overview

Configuring a pre-commit code review requires:

Configuring a Test Configuration for Pre-Commit Code Reviews

The Code Review Test Configuration detects code changes and prepares them for review. We recommend configuring a single Test Configuration and sharing it across the team using Team Server. This streamlines configuration and updating. 

You can create a Test Configuration that is dedicated to Code Review, or have a Test Configuration that checks for Code Reviews as well as performs other analyses.

To configure a Test Configuration that detects code changes and prepares them for review:

  1. Open the Test Configurations dialog by choosing Parasoft> Test Configurations or by choosing Test Configurations in the drop-down menu on the Test Using toolbar button.
  2. Duplicate an existing Test Configuration (such as Built-in> Code Review> Pre-Commit) or create a new one.
  3. In the Scope tab, choose Test only files added or modified locally.
  4. Also in the Scope tab, review the File Filters> Path options settings and adjust them if desired. For details on these Test Configuration settings, see Configuring Test Configurations.
  5. If your reporting preferences are not already set to use a unique session tag for code review scans, go to the Common tab, enable Override Session Tag, then choose one of the preconfigured identifiers, or specify your own. This is the tag that will be assigned to all code reviews that stem from this Test Configuration.
  6. At the top of the Code Review tab:
    1. Check Enable Code Review Scanner.
    2. If you want the report to include code review results from all available team scanners, enable  Generate comprehensive report (includes all scanners). This option is not typically used for pre-commit code reviews. If this is not enabled, the report will include only results for the specified session tag.
    3. Enable Auto publish reviews if you want review tasks to be "published" (uploaded) automatically after this Test Configuration is run. This is recommended for pre-commit code reviews.
    4. From the Generate tasks with priority box, indicate the priority that should be assigned to all code review tasks that are created using this Test Configuration.
  7. (Optional) If you want the reviews automatically assigned, use the Authors, Reviewers, Monitors, and Filters tabs to define how you want your code reviews assigned. Reviewers and monitors can be assigned to specific authors, or to specific project areas. If you do not specify options here, each author needs to select the appropriate reviewer for each submitted review.
  8. (Optional) In the Code Review> Filters tab, modify the following options if desired:
  9. Click Apply to commit the new Test Configuration.
  10. Share the Test Configuration by right-clicking it, then choosing Upload to Team Server from the shortcut menu.

Submitting Code for Review - Interactive Desktop Execution

Each developer should perform the following steps after completing new/modified code that is ready for review:

  1. In the project tree, select the node that represents the changes you want reviewed.
  2. Run your designated Code Review Test Configuration. This should be in the Team category.
  3. If you enabled the Show user assistant during scanner run option in the Code Review Preferences panel (strongly recommended), C++test will display the Code Review assistant.


    You can use this dialog to:
  4. If your Code Review Test Configuration does not have Auto publish reviews enabled, upload the results to Team Server as follows:

The designated reviewer will then be alerted that code is ready for review. The reviewer can perform the review as described in Reviewers - Reviewing Code Modifications.

After the review is completed, the author can respond as described in Authors - Examining and Responding to Review Comments.

Adding New Files to the Code Review Package

To add selected files to an existing code review package:

  1. In the project tree, right-click the package to which you want to add files, then choose Parasoft> Add to> Code Review from the shortcut menu.
  2. Complete the Code Review Assistant dialog.

Defining Reviewers, Authors, and Monitors with a Properties File

In addition to specifying code review users directly in the Test Configuration and adding reviewers "on-the-fly" in the Code Review Assistant dialog, you can also define code review users in a .properties file. This can be useful if your review process involves a large number of team members and you can automatically generate a database of your team members.

To define reviewers with a properties file:

  1. Prepare an empty properties file
  2. Add to it the following initial required data: Code Review 
  3. Begin defining the list of users—either manually, or using a custom script that pulls the appropriate information automatically. Each user must have an index, and then properties, such as name, roles, and monitored.locations (for monitors only). Available roles are 'a' (author), 'm' (monitor), 'r' (reviewer). For example:
    com.parasoft.xtest.codereview.scanner.crusers.2.monitored.locations=**/src/**, **/include/** 
  4. Publish the prepared file on a dedicated HTTP server. If you will be automatically regenerating this based on user database, use a file location that will allow such regeneration.
  5. Open the Test Configuration dialog and create new configuration by duplicating the "Pre Commit" Test Configuration.
  6. Right-click that Test Configuration, choose New Child, then type the URL address to your HTTP parent configuration.
  7. Refresh the Test Configuration manager and verify that any added monitors are displayed.
  8. Publish it on Team Server.

Here is a sample properties file:

com.parasoft.xtest.codereview.scanner.crusers.13.reviewers=mark_A, mark_B
com.parasoft.xtest.codereview.scanner.crusers.13.reviewed.locations=**/test/*.txt, project_A/**

Note that:

Adding Post-Commit Scans To Your Pre-Commit Process

Some teams who submit code for review via a pre-commit process also like to perform a post-commit nightly scan to:

For details on how to accomplish this, see Running Post-Commit Scans with a Pre-Commit.