Reference Node Guide

The Reference Node is a versatile feature in ReAPI that enables you to reuse steps or entire flows by referencing other test cases. This is especially useful for common tasks, such as obtaining an authentication token or performing setup actions, as it saves time, ensures consistency, and reduces redundancy across test cases.

Types of Reusability: Clone vs. Ref

When you add a Reference Node, you have two options for reusability:

  1. Clone:

    • Functionality: Creates an inline copy of all nodes within the referenced test case. The cloned nodes are fully independent in the current test case, meaning any modifications you make do not affect the original test case.
    • Use Case: Ideal for using a test case as a template. For instance, if you have a common request pattern, cloning allows you to use it as a base and customize it as needed.
    • Recommendation: To streamline test creation, it’s recommended to create a “Template” folder specifically for reusable patterns. This folder can contain test cases that are frequently cloned, making it easy to start from pre-defined structures without affecting other tests.
  2. Ref:

    • Functionality: Directly references the original reusable test case. Any updates made to the referenced test case will reflect wherever it’s used, ensuring consistency across test cases.
    • Use Case: Useful when you want to maintain a single source of truth. For example, referencing a “Get Authentication Token” test case means you’ll only need to update the token logic once, and all dependent tests will inherit the change.

Debug Node Flag

The Reference Node also has an optional Debug Node flag, which allows you to control how the node behaves within a test runner:

  • Debug Node: When flagged, the node will be skipped in the test runner, making it useful for shared setup steps. For example, if you need an authentication token available to multiple test cases within a test runner, you can add the Reference Node with the Debug Node flag. This way, the referenced “Get Authentication Token” test case runs only once, like a beforeAll setup step, and the output is shared across all tests.

Example Workflow with Reference Nodes

  1. Create a Reusable Test Case: Let’s say you create a reusable test case named “Get Authentication Token” and flag it as reusable.

  2. Using Clone for Templates: You create another test case that follows a specific request structure, like creating a user profile. You clone a template test case for this pattern and customize the cloned nodes to fit the new test case, making changes independently of the original.

  3. Using Ref with Debug Node: In multiple test cases, you reference the “Get Authentication Token” test case without cloning it. To avoid redundant calls in the test runner, you flag this Reference Node as a Debug Node, ensuring it executes only once. This setup shares the token across all tests in the runner without re-running the token request in each test.

Benefits of Using Reference Nodes with Clone and Ref Options

The dual options of Clone and Ref make Reference Nodes a powerful tool for maintaining flexible, efficient, and easily updatable test cases. Cloning helps you apply common patterns with custom modifications, while referencing maintains centralized logic across multiple tests. The Debug Node flag further enhances efficiency by minimizing redundant actions, particularly in shared setups within test runners.