Files
fn-serverless/docs/developers/testing.md
Travis Reeder 5a2602d42e Updated docs, cleaned things up, DRY's up function format stuff. (#688)
* Updated docs, cleaned things up, DRY's up function format stuff.

* deleted files

* updated bad link
2018-01-16 14:45:44 -08:00

1.3 KiB

Testing Functions

fn has testing built in that allows you to create inputs and expected outputs and verify the expected output with actual output.

Write a Test File

Create a file called test.json in your functions directory (beside your func.yaml file). Here's a simple example:

{
    "tests": [
        {
            "input": {
                "body": {
                    "name": "Johnny"
                }
            },
            "output": {
                "body": {
                    "message": "Hello Johnny"
                }
            }
        },
        {
            "input": {
                "body": ""
            },
            "output": {
                "body": {
                    "message": "Hello World"
                }
            }
        }
    ]
}

The example above has two tests, one with the following input:

{
    "name": "Johnny"
}

and a second one with no input.

The first one is expected to return a json response with the following:

{
    "message": "Hello Johnny"
}

And the second should return:

{
    "message": "Hello World"
}

Run Tests

This is simply running:

fn test

in your function directory.

You can also test against a remote fn server by using the --remote flag. eg:

fn test --remote myapp