---
name: codeengine-fun-test-local
title: Testing Code Engine functions locally
description: IBM Cloud&reg; Code Engine functions are created from code snippets and so testing them locally isn't as straightforward as testing an app or job locally. One way that you can test functions locally by creating a wrapper for the code snippet and then running it locally.
last-updated: 2026-01-27
---

> ## Documentation Index
> The table of contents for this documentation set is at https://cloud.ibm.com/docs/codeengine?format=markdown
> The index for all IBM Cloud docs is at: https://cloud.ibm.com/docs/llms.txt
> Use these files to discover more information as needed.

# Testing Code Engine functions locally
{: #fun-test-local}

IBM Cloud&reg; Code Engine functions are created from code snippets and so testing them locally isn't as straightforward as testing an app or job locally. One way that you can test functions locally by creating a wrapper for the code snippet and then running it locally. 
{: shortdesc}

To test your code with a wrapper, follow these general steps.

1. Create a directory called `test-local`.
2. Create a subdirectory called `func`.
3. Copy your function code into the `func` subdirectory.
4. Copy either the Python or Node.js wrapper code into the parent directory. 
5. Create a configuration file as JSON objects, similar to what is passed to by Code Engine to the [function when it is invoked](https://cloud.ibm.com/docs/codeengine?topic=codeengine-fun-work&format=markdown#functions-data).
6. Run the wrapper code with the configuration file as a parameter.

You can use the following wrappers or create your own.

## Python wrapper
{: #fun-test-python}

```python
# syntax: python wrapper.py params.json

# import the Code Engine function: func/__main__.py
from func.__main__ import main
import sys, json

if __name__ == "__main__":
    # open file, read JSON config
    with open(str(sys.argv[1])) as confFile:
        params=json.load(confFile)
    # invoke the Code Engine function and print the result
    print(main(params))
```
{: pre}

## Node.js wrapper
{: #fun-test-nodejs}

```nodejs
// syntax: node wrapper.js params.json

// require the Code Engine function: func/main.js
var func=require('./func/main.js')

// read the file with function parameters
const fs = require("fs");
const data = fs.readFileSync(process.argv[2]);

// invoke the Code Engine function and log the result
console.log(func.main(JSON.parse(data)));
```
{: pre}