---
schema_version: "1"
id: 0a33219859b0fd55474a24f10d89f72aa8f94da69477b8179304773ca24c8a44
title: testCanvasLifecycle(lifecycleHandler, mockRenderContext)
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_canvas_Test_testCanvasLifecycle.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_canvas_Test_testCanvasLifecycle.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 9e7b3b6cc65193191fbee5f9b2c9a58b00a5f773b5bcbff3c15efce4619c8f7d
description: Calls the Canvas test framework to invoke a CanvasLifecycleHandler with the provided RenderContext.
---
# testCanvasLifecycle(lifecycleHandler, mockRenderContext)

Calls the Canvas test framework to invoke a CanvasLifecycleHandler with the provided RenderContext.

## Signature

public static Void testCanvasLifecycle(Canvas.CanvasLifecycleHandler lifecycleHandler,Canvas.RenderContext mockRenderContext)

## Parameters

- **lifecycleHandler**:
    
    Type: [Canvas.CanvasLifecycleHandler](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_interface_canvas_CanvasLifecycleHandler.htm "Implement this interface to control context information and add custom behavior during the application render phase.")
    
    Specifies the CanvasLifecycleHandler implementation that you need to invoke.
- **mockRenderContext**:
    
    Type: [Canvas.RenderContext](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_interface_canvas_RenderContext.htm "A wrapper interface that is used to retrieve application and environment context information.")
    
    Specifies the RenderContext information that you need to provide to the invoked CanvasLifecycleHandler. If null is provided for this parameter, the canvas framework generates and uses a default mock RenderContext.

## Return Value

Type: Void

## Usage

Use this method to invoke an implementation of [Canvas.CanvasLifecycleHandler.onRender(renderContext)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_canvas_CanvasLifecycleHandler_onRender.htm "Invoked when a canvas app is rendered. Provides the ability to set and retrieve canvas application and environment context information during the application render phase.") with a mock [Canvas.RenderContext](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_interface_canvas_RenderContext.htm "A wrapper interface that is used to retrieve application and environment context information.") that you provide.

## Example

The following example creates an Apex test class that uses maps to represent mock application and environment context data. The mock RenderContext object is then used to invoke a CanvasLifecycleHandler object. In this example, the CanvasLifecycleHandler is defined as MyCanvasListener, which is example implementation provided in [Canvas.RenderContext](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_interface_canvas_CanvasLifecycleHandler.htm "Implement this interface to control context information and add custom behavior during the application render phase.").

@IsTest
public with sharing class CanvasRendercontextTest {
    @IsTest
    static void testRenderContext(){
        // Set some application context data in a Map
        Map<String,String\> appValues = new Map<String,String\>();
        appValues.put(Canvas.Test.KEY\_NAMESPACE,'alternateNamespace');
        appValues.put(Canvas.Test.KEY\_VERSION,'3.0');
        
        // Set some environment context data in a MAp
        Map<String,String\> envValues = new Map<String,String\>();
        envValues.put(Canvas.Test.KEY\_DISPLAY\_LOCATION,'Chatter');
        envValues.put(Canvas.Test.KEY\_LOCATION\_URL,'https://MyDomainName.my.salesforce.com/\_ui/core/chatter/ui/ChatterPage');
        
        // Create a mock RenderContext using the test application and environment context data Maps
        Canvas.RenderContext mock = Canvas.Test.mockRenderContext(appValues,envValues);
        
        // Set some custom params on the mock RenderContext
        mock.getEnvironmentContext().setParametersAsJSON('{"param1":1,"boolParam":true,"stringParam":"test string"}');
        
        // Create a CanvasLifecycleHandler
        MyCanvasListener handler = new MyCanvasListener();
        
        // Use the mock RenderContext to invoke the CanvasLifecycleHandler
        Canvas.Test.testCanvasLifecycle(handler,mock);
	}
}

#### See Also

- [_Canvas Developer Guide_: Testing Your CanvasLifecycleHandler Implementation](https://developer.salesforce.com/docs/atlas.en-us.264.0.platform_connect.meta/platform_connect/canvas_testing_your_canvaslifecyclehandler.htm "Canvas Developer Guide: Testing Your
    CanvasLifecycleHandler Implementation - HTML (New Window)")