# test

Learn how to execute actions conditionally.

This action executes different actions depending on whether a condition is true or false, allowing the workflow to branch based on project settings, user input, or other runtime values.

## Example

The following template checks the [detected platform](/reference/cli/templates/variables#project-platform-prop) and prints a message accordingly:

**template.json5**

```json5
{
  "$schema": "https://schema.croct.com/json/v1/template.json",
  "title": "Platform check",
  "description": "Checks the detected platform.",
  "actions": [
    {
      "name": "test",
      "condition": "${project.platform !== 'unknown'}",
      "then": {
        "name": "print",
        "message": "Detected platform: ${project.platform}"
      },
      "else": {
        "name": "print",
        "message": "No supported platform detected."
      }
    }
  ]
}
```

To apply this template, run:

```sh
croct use template.json5
```

## Properties

These are the supported properties:

- `name`: `string`

  The action identifier. Always `test` for this action.

- `condition`: `boolean`

  An [expression](/reference/cli/templates/expressions) that determines which branch to execute.

- `then`: `Action | Array<Action>` (see [Action](/reference/cli/templates/actions), [Array\<Action>](/reference/cli/templates/actions))

  The actions to execute when the condition is true.

  Accepts a single action or a list of actions.

- `else`: `Action | Array<Action>` (optional) (see [Action](/reference/cli/templates/actions), [Array\<Action>](/reference/cli/templates/actions))

  The actions to execute when the condition is false.

  Accepts a single action or a list of actions. When omitted, nothing happens if the condition is false.

## Explore

- [Fail](/reference/cli/templates/actions/fail): Learn how to abort when a condition is not met.
- [Repeat](/reference/cli/templates/actions/repeat): Learn how to iterate over a list of items.
- [Define](/reference/cli/templates/actions/define): Learn how to define variables for conditions.
- [Check dependency](/reference/cli/templates/actions/check-dependency): Learn how to check a dependency as a condition.
