# CMake presets: What is a testpreset for?

**URL:** https://discourse.cmake.org/t/cmake-presets-what-is-a-testpreset-for/5404
**Category:** Code
**Created:** [April 7, 2022, 6:41pm UTC](https://discourse.cmake.org/t/cmake-presets-what-is-a-testpreset-for/5404 "2022-04-07T18:41:52Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [April 7, 2022, 6:41pm UTC](https://discourse.cmake.org/t/cmake-presets-what-is-a-testpreset-for/5404/1 "2022-04-07T18:41:52Z")

</div>

If you want to use the presets in an `IDE`, you only need the `configurePresets `, or not?

If you do **not** know, what the `binary directory` is, you need the `buildPresets ` too on console.

And with the `cmake --build builddirpath --taget test` you need **no** `testPresets `!

If the user has a `Multi-Config `project created, than the user may switch with `--config` i.e. from `Debug` to `Release`.

```cmake
cmake . --preset=ninja-multi cmake --build --preset=ninja-multi --config Release
cmake --build --preset=ninja-multi --config Release --target help # or test, install, ... 
ctest --preset=ninja-multi --build-config Release

```

And perheps, see your preset list available for your host:  
use `cmake . --list-presets=all`

But this does not work out of the box! see [this post](https://discourse.cmake.org/t/how-to-prevent-that-cmake-list-presets-all-hide-presets-not-usable-on-my-host/5395)

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [April 8, 2022, 5:45am UTC](https://discourse.cmake.org/t/cmake-presets-what-is-a-testpreset-for/5404/2 "2022-04-08T05:45:07Z")

</div>

see for example [remove garbage from mircosoft presets · ClausKlein/cpp\_starter\_project@c4cf772 · GitHub](https://github.com/ClausKlein/cpp_starter_project/commit/c4cf772ea5545a53ac74e63888a99633622b05e5)

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [April 9, 2022, 12:55pm UTC](https://discourse.cmake.org/t/cmake-presets-what-is-a-testpreset-for/5404/3 "2022-04-09T12:55:38Z")

</div>

@kyle.edwards

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [August 15, 2023, 2:08pm UTC](https://discourse.cmake.org/t/cmake-presets-what-is-a-testpreset-for/5404/4 "2023-08-15T14:08:44Z")

</div>

If used in `workflow` presets, the `testPresets` makes sense. i.e.:

cat `CMakePresets.json`

```json
{
  "version": 6,
  "cmakeMinimumRequired": {
    "major": 3,
    "minor": 23,
    "patch": 0
  },
  "configurePresets": [
    {
      "name": "default",
      "displayName": "Default develop test Config",
      "description": "Default build using Ninja generator",
      "generator": "Ninja",
      "binaryDir": "${sourceParentDir}/build/test",
      "installDir": "${sourceParentDir}/stagedir",
      "cacheVariables": {
        "CMAKE_PREFIX_PATH": {
          "type": "path",
          "value": "${sourceParentDir}/stagedir"
        },
        "CMAKE_CXX_STANDARD": "20",
        "CMAKE_BUILD_TYPE": "Release",
        "CMAKE_DEBUG_POSTFIX": "D",
        "CPM_USE_LOCAL_PACKAGES": "NO",
        "BUILD_SHARED_LIBS": "YES",
        "TEST_INSTALLED_VERSION": "YES"
      },
      "environment": {
        "CPM_USE_LOCAL_PACKAGES": "YES",
        "PATH": "$env{HOME}/.local/bin${pathListSep}$penv{PATH}",
        "LD_LIBRARY_PATH": "${sourceParentDir}/stagedir/lib${pathListSep}penv{LD_LIBRARY_PATH}"
      }
    }
  ],
  "buildPresets": [
    {
      "name": "default",
      "configurePreset": "default"
    }
  ],
  "testPresets": [
    {
      "name": "default",
      "configurePreset": "default",
      "output": {"outputOnFailure": true},
      "execution": {"noTestsAction": "error", "stopOnFailure": true}
    }
  ],
  "packagePresets": [
    {
      "name": "default",
      "configurePreset": "default",
      "generators": [
        "TGZ"
      ]
    }
  ],
  "workflowPresets": [
    {
      "name": "default",
      "steps": [
        {
          "type": "configure",
          "name": "default"
        },
        {
          "type": "build",
          "name": "default"
        },
        {
          "type": "test",
          "name": "default"
        }
      ]
    }
  ]
}

```
