mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Update for testing functions.
This commit is contained in:
79
docs/testing.md
Normal file
79
docs/testing.md
Normal file
@@ -0,0 +1,79 @@
|
||||
# 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:
|
||||
|
||||
```json
|
||||
{
|
||||
"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:
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "Johnny"
|
||||
}
|
||||
```
|
||||
|
||||
and a second one with no input.
|
||||
|
||||
The first one is expected to return a json response with the following:
|
||||
|
||||
```json
|
||||
{
|
||||
"message": "Hello Johnny"
|
||||
}
|
||||
```
|
||||
|
||||
And the second should return:
|
||||
|
||||
```json
|
||||
{
|
||||
"message": "Hello World"
|
||||
}
|
||||
```
|
||||
|
||||
## Run Tests
|
||||
|
||||
This is simply running:
|
||||
|
||||
```sh
|
||||
fn test
|
||||
```
|
||||
|
||||
in your function directory.
|
||||
|
||||
You can also test against a remote `fn` server by using the `--remote` flag. eg:
|
||||
|
||||
```sh
|
||||
fn test --remote myapp
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user