Contact Us 1-800-596-4880

Testing Connectors

Learn how to test your connector. Testing is an important part of the development process, and it helps you ensure that your connector works as expected. Testing your connector involves generating tests, running tests, and validating the connector within the platform.

Generate Tests (Beta)

Generating tests is a pilot or beta service that is subject to the Beta Services Terms at Agreements - Salesforce.com or a written Unified Pilot Agreement if executed by Customer, and applicable terms in the Product Terms Directory. Use of this pilot or beta service is at the Customer’s sole discretion.

You can generate tests without or with AI assistance (available when using Cursor). The tests are connectivity model tests, which are split into data files and actual test files, creating a structured project. These tests include:

  • Tests for all use cases: This includes basic connectivity model tests, pagination tests, and negative test cases.

  • Mock server for negative test cases: A mock server is used for negative test cases because replicating them against a live server is not always feasible.

  • Reusable test data: Test data is stored in separate files for easy reuse.

  • Self-contained tests for connector operations: These tests function independently. For example, if a connector has POST, GET, PATCH, and DELETE operations for /invoices, a self-contained test case can be generated, and the report reflects this.

Here’s an example of a generated test file for /calendars/{calendarId}/acl/{ruleId} - PATCH in a Google Calendar connector, which demonstrates the generation of parent operations, rule creation, and resource deletion:

%dw 2.8
import * from dw::test::Asserts
import * from dw::test::Tests
import * from dw::Runtime
import * from com::mulesoft::connectivity::Model
import * from com::mulesoft::connectivity::transport::Http
import * from com::mulesoft::connectivity::Metadata

import * from utils::ConnectionOperations

import * from com::mulesoft::connectivity::zzz4::operations::O_calendars_post
import * from com::mulesoft::connectivity::zzz4::operations::O_calendars__calendarId__get
import * from com::mulesoft::connectivity::zzz4::operations::O_calendars__calendarId__patch
import * from com::mulesoft::connectivity::zzz4::operations::O_calendars__calendarId__delete
import * from com::mulesoft::connectivity::zzz4::operations::O_calendars__calendarId__acl_post
import * from com::mulesoft::connectivity::zzz4::operations::O_calendars__calendarId__acl_get
import * from com::mulesoft::connectivity::zzz4::operations::O_calendars__calendarId__acl__ruleId__get
import * from com::mulesoft::connectivity::zzz4::operations::O_calendars__calendarId__acl__ruleId__patch
import * from com::mulesoft::connectivity::zzz4::operations::O_calendars__calendarId__acl__ruleId__delete
import * from data::calendars_post_request
import * from data::calendars__calendarId__get_request
import * from data::calendars__calendarId__patch_request
import * from data::calendars__calendarId__delete_request
import * from data::calendars__calendarId__acl_post_request
import * from data::calendars__calendarId__acl_get_request
import * from data::calendars__calendarId__acl__ruleId__get_request
import * from data::calendars__calendarId__acl__ruleId__patch_request
import * from data::calendars__calendarId__acl__ruleId__delete_request

var V_calendars_post_response = O_calendars_post.executor(V_calendars_post_request(), connection)

var V_calendars__calendarId__get_response = O_calendars__calendarId__get.executor(V_calendars__calendarId__get_request(CALENDARID), connection)

var V_calendars__calendarId__patch_response = O_calendars__calendarId__patch.executor(V_calendars__calendarId__patch_request(CALENDARID), connection)

var V_calendars__calendarId__delete_response = O_calendars__calendarId__delete.executor(V_calendars__calendarId__delete_request(CALENDARID), connection)

var V_calendars__calendarId__acl_post_response = O_calendars__calendarId__acl_post.executor(V_calendars__calendarId__acl_post_request(CALENDARID), connection)

var V_calendars__calendarId__acl_get_response = O_calendars__calendarId__acl_get.executor(V_calendars__calendarId__acl_get_request(CALENDARID), connection)

var V_calendars__calendarId__acl__ruleId__get_response = O_calendars__calendarId__acl__ruleId__get.executor(V_calendars__calendarId__acl__ruleId__get_request(CALENDARID,RULEID), connection)

var V_calendars__calendarId__acl__ruleId__patch_response = O_calendars__calendarId__acl__ruleId__patch.executor(V_calendars__calendarId__acl__ruleId__patch_request(CALENDARID,RULEID), connection)

var V_calendars__calendarId__acl__ruleId__delete_response = O_calendars__calendarId__acl__ruleId__delete.executor(V_calendars__calendarId__acl__ruleId__delete_request(CALENDARID,RULEID), connection)
---
"/calendars/{calendarId}/acl/{ruleId} tests" describedBy [
    "/calendars - POST Successful Execution" in do {
        V_calendars_post_response.value.status must equalTo(200)
    },
    "/calendars/{calendarId} - GET Successful Execution" in do {
        V_calendars__calendarId__get_response.value.status must equalTo(200)
    },
    "/calendars/{calendarId} - PATCH Successful Execution" in do {
        V_calendars__calendarId__patch_response.value.status must equalTo(200)
    },
    "/calendars/{calendarId} - DELETE Successful Execution" in do {
        V_calendars__calendarId__delete_response.value.status must equalTo(200)
    },
    "/calendars/{calendarId}/acl - POST Successful Execution" in do {
        V_calendars__calendarId__acl_post_response.value.status must equalTo(200)
    },
    "/calendars/{calendarId}/acl - GET Successful Execution" in do {
        V_calendars__calendarId__acl_get_response.value.status must equalTo(200)
    },
    "/calendars/{calendarId}/acl/{ruleId} - GET Successful Execution" in do {
        V_calendars__calendarId__acl__ruleId__get_response.value.status must equalTo(200)
    },
    "/calendars/{calendarId}/acl/{ruleId} - PATCH Successful Execution" in do {
        V_calendars__calendarId__acl__ruleId__patch_response.value.status must equalTo(200)
    },
    "/calendars/{calendarId}/acl/{ruleId} - DELETE Successful Execution" in do {
        V_calendars__calendarId__acl__ruleId__delete_response.value.status must equalTo(200)
    },
]

If any operation is missing, a self-sustained test case can’t be generated, and the report indicates this. Here’s an example of a report for Google Calendar connector operations, which illustrates the status (SUCCESS and PARTIAL_SUCCESS) and messages indicating missing operations or complete test generation. This report is generated with the generated tests:

OPERATION NAME                STATUS           MESSAGE
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
calendar.calendars.delete     SUCCESS          Complete test generated
calendar.calendarList.patch   SUCCESS          Complete test generated
calendar.calendarList.insert  PARTIAL_SUCCESS  Missing DELETE operation - Self sustained testcase not generated - Resource DELETION needed
calendar.calendarList.list    PARTIAL_SUCCESS  Missing DELETE operation - Self sustained testcase not generated - Resource DELETION needed
calendar.events.get           SUCCESS          Complete test generated
calendar.calendarList.update  SUCCESS          Complete test generated
calendar.events.list          SUCCESS          Complete test generated
calendar.colors.get           PARTIAL_SUCCESS  Missing CREATE and DELETE operation - Self sustained testcase not generated - Both Resource CREATION and DELETION needed
calendar.acl.update           SUCCESS          Complete test generated
calendar.calendarList.get     SUCCESS          Complete test generated
calendar.acl.list             SUCCESS          Complete test generated
calendar.calendars.update     SUCCESS          Complete test generated
calendar.calendarList.delete  SUCCESS          Complete test generated
calendar.events.move          SUCCESS          Complete test generated
calendar.events.insert        SUCCESS          Complete test generated
calendar.freebusy.query       PARTIAL_SUCCESS  Missing DELETE operation - Self sustained testcase not generated - Resource DELETION needed
calendar.calendarList.watch   PARTIAL_SUCCESS  Missing DELETE operation - Self sustained testcase not generated - Resource DELETION needed
calendar.acl.delete           SUCCESS          Complete test generated
calendar.calendars.clear      SUCCESS          Complete test generated
calendar.events.watch         SUCCESS          Complete test generated
calendar.settings.watch       PARTIAL_SUCCESS  Missing DELETE operation - Self sustained testcase not generated - Resource DELETION needed
calendar.events.patch         SUCCESS          Complete test generated
calendar.settings.get         PARTIAL_SUCCESS  Missing CREATE and DELETE operation - Self sustained testcase not generated - Both Resource CREATION and DELETION needed
calendar.acl.watch            SUCCESS          Complete test generated
calendar.calendars.patch      SUCCESS          Complete test generated
calendar.calendars.get        SUCCESS          Complete test generated
calendar.calendars.insert     PARTIAL_SUCCESS  Missing DELETE operation - Self sustained testcase not generated - Resource DELETION needed
calendar.channels.stop        PARTIAL_SUCCESS  Missing DELETE operation - Self sustained testcase not generated - Resource DELETION needed
calendar.settings.list        PARTIAL_SUCCESS  Missing CREATE and DELETE operation - Self sustained testcase not generated - Both Resource CREATION and DELETION needed
calendar.acl.patch            SUCCESS          Complete test generated
calendar.events.delete        SUCCESS          Complete test generated
calendar.events.update        SUCCESS          Complete test generated
calendar.acl.get              SUCCESS          Complete test generated
calendar.acl.insert           SUCCESS          Complete test generated
calendar.events.quickAdd      SUCCESS          Complete test generated
calendar.events.import        SUCCESS          Complete test generated
calendar.events.instances     SUCCESS          Complete test generated

Generate Tests Without AI Assistance

If you generate tests without AI assistance, the test data will have placeholder data.

  1. Open your IDE and go to Connector Builder - Editor.

  2. If you haven’t generated your connector yet, click Generate > Generate Anypoint Connector.

  3. Click Generate > Generate Tests.

  4. Fill out the required fields for your authentication type.

  5. Click Generate Tests.

Generate Tests With AI Assistance (Cursor)

If you generate tests with AI assistance, AI helps generate test data.

  1. Ensure Enable Ai Assisted Workflows is enabled.

  2. Open your IDE and go to Connector Builder - Editor.

  3. If you haven’t generated your connector yet, click Generate > Generate Anypoint Connector.

  4. Click Generate > Generate Tests.

  5. Fill out the required fields for your authentication type.

  6. In Developer Documentation URL, enter the URL that will be used as the source for the AI test data generation.

  7. Click Help me with test data generation. This copies a prepared prompt to your clipboard, which you can manually paste into the Cursor chat window.

  8. Open the Cursor chat window (if not already open) and paste the copied prompt. Ensure you’re in Agent mode.

    The agent analyzes the provided resources, and generates semantically accurate data for existing tests.

Run Tests

You can run tests without or with AI assistance (available when using Cursor). If you use AI assistance, you can make your generated test data semantically accurate. If you don’t use AI assistance, the data is only schematically accurate and requires manual effort.

Run Tests Without AI Assistance

  1. Manually edit data files to provide relevant data for test cases.

  2. To resolve failed tests, log the response to debug issues, for example:

    var V_calendars__calendarId__acl_get_response = log(O_calendars__calendarId__acl_get.executor(V_calendars__calendarId__acl_get_request(CALENDARID), connection))
  3. Run tests by using the mvn test command.

Run Tests With AI Assistance (Cursor)

  1. Ensure Enable Ai Assisted Workflows is enabled.

  2. A rule file is generated to assist you in creating test data, at <project root>/.cursor/rules/test-data-generation-rules.

  3. Open the Cursor chat window and ask the agent to create sample test data according to the generated rule file, referring to SaaS documentation as needed.

  4. To resolve failed tests, log the response to debug issues, for example:

    var V_calendars__calendarId__acl_get_response = log(O_calendars__calendarId__acl_get.executor(V_calendars__calendarId__acl_get_request(CALENDARID), connection))
  5. Run tests by using the mvn test command.

Validate the Connector

Before you release your connector, you can install the connector in the platform to make sure it works as expected.

Validate the Connector in Anypoint Platform

To validate the connector in Anypoint Platform, you can install the connector in Anypoint Studio or Anypoint Code Builder.

  1. In the pom.xml file, ensure mule-maven-plugin-version is 4.6.0 or later.

  2. In the pom.xml file, add your connector dependency, for example:

    <dependencies>
     <dependency>
      <groupId>com.mulesoft.connectivity.flights</groupId>
      <artifactId>flights-anypoint-connector-model</artifactId>
      <version>0.0.3-SNAPSHOT</version>
      <classifier>mule-plugin</classifier>
     </dependency>
    </dependencies>

Now, your connector appears in Anypoint Studio or Anypoint Code Builder and you can test the connector functionality.