RemoveUnit Method

Applies to TestComplete 15.65, last modified on July 17, 2024


Use the RemoveUnit method to remove a specified script unit from the TestComplete project represented by the ProjectIntegration object.



ProjectIntegrationObj An expression, variable or parameter that specifies a reference to a ProjectIntegration object
FileName [in]    Required    String    
Result None

Applies To

The method is applied to the following object:


The method has the following parameter:


Specifies the fully qualified name of the script unit file to be removed from the project.

Result Value



When removing a script unit, TestComplete only removes this unit from the Script project item. It does not remove the script unit file.


The following example demonstrates how you can work with script units of the project currently opened in TestComplete.

Visual Basic

Sub Test()

  Dim TestCompleteApp As TestCompleteApplication
  Dim IntegrationObject As ItcIntegration
  Dim LastResult As ItcIntegrationResultDescription

  ' Creates the application object
  Set TestCompleteApp = CreateObject("TestComplete.TestCompleteApplication.15")

  ' Obtains the integration object
  Set IntegrationObject = TestCompleteApp.Integration

  ' Opens the project
  ProjectPath = "C:\Work Folder\TestSuite\TestSuite.pjs"
    IntegrationObject.OpenProjectSuiteEx (ProjectPath)

  ' Needed to process errors
  On Error GoTo Err_Label

    ' Obtains the ProjectIntegration object
    Set ProjectIntegration = IntegrationObject.Project("TestProject_VB")
    ' Specifies the script unit file
    UnitPath = "C:\Work Folder\TestSuite\TestProject_VB\Script\Test4_VB.svb"
    ' Checks whether the project contains the specified script unit
    If ProjectIntegration.HasUnit(UnitPath) Then
      ' If the project contains the unit
      ' Displays an informative message
      MsgBox "The project already contains the specified script unit"
      ' If the project does not contain the unit
      ' Adds the unit to the project
      ProjectIntegration.AddUnit (UnitPath)


      ' Removes the added unit from the project
      ProjectIntegration.RemoveUnit (UnitPath)
    End If

    ' Process errors
    If Err.Number <> 0 Then
      MsgBox Err.Description, vbCritical, "Error"
    End If

  ' Closes TestComplete

End Sub


// Add the following lines to your code
using System.Runtime.InteropServices;
using TestComplete;

public partial class Form1 : Form
  public Form1()

  private void btn_Connect_Click(object sender, EventArgs e)
    const string TCProgID = "TestComplete.TestCompleteApplication.15";
    string ProjectSuitePath = "C:\\Work Folder\\TestSuite\\TestSuite.pjs";
    string ProjectPath = "C:\\Work Folder\\TestSuite\\TestProject_CS";
    string ProjectName = "TestProject_CS";
    object TestCompleteObject = null;
    string FilePath;

    // Obtains access to TestComplete
      TestCompleteObject = Marshal.GetActiveObject(TCProgID);
        TestCompleteObject = Activator.CreateInstance(Type.GetTypeFromProgID(TCProgID));

    if (TestCompleteObject == null) return;

    // Obtains ITestCompleteCOMManager
    TestComplete.ITestCompleteCOMManager TestCompleteManager = (TestComplete.ITestCompleteCOMManager)TestCompleteObject;
    // Obtains Integration object
    TestComplete.ItcIntegration IntegrationObject = TestCompleteManager.Integration;
    // Loads the project suite
      // Obtains ProjectIntegration object
      TestComplete.ItcProjectIntegration Project = IntegrationObject.get_Project(ProjectName);

      // Shows the Open File dialog allowing to select a script unit to add to the project
      OpenFileDialog.InitialDirectory = ProjectPath + "\\Script";
      OpenFileDialog.Filter = "C#Script files|*.scs";
      if (OpenFileDialog.ShowDialog() == DialogResult.OK)
        FilePath = OpenFileDialog.FileName;
        if (Project.get_HasUnit(FilePath))
          // If the project already contains the selected unit
          // Displays the informative message
          MessageBox.Show("The project already contains this script unit");
          // If the project does not contain the selected unit
          // Adds the unit to the project


          // Removes the added unit from the project
    catch (System.Runtime.InteropServices.COMException ex)
      System.Windows.Forms.MessageBox.Show("An exception occurred: " + ex.Message);
      // Closes TestComplete
      // Releases COM objects

See Also

Working With TestComplete via COM - Overview
AddUnit Method
HasUnit Property

Highlight search results