diff --git a/scripts/cmake/test/OgsTest.cmake b/scripts/cmake/test/OgsTest.cmake
index 538be4c3d99221732a3be9a0bbe98c80bdd255d1..29ff47437a99bda10795ebbd49c8715488bfe7c4 100644
--- a/scripts/cmake/test/OgsTest.cmake
+++ b/scripts/cmake/test/OgsTest.cmake
@@ -52,11 +52,21 @@ function(OgsTest)
         endif()
     endif()
 
+    set(_exe_args -r ${OgsTest_SOURCE_DIR}
+                  ${OgsTest_SOURCE_DIR}/${OgsTest_NAME}
+    )
+    string(REPLACE "/" "_" TEST_NAME_UNDERSCORE ${TEST_NAME})
     add_test(
-        NAME ${TEST_NAME} WORKING_DIRECTORY "${OgsTest_BINARY_DIR}"
-        COMMAND ${OgsTest_WRAPPER} $<TARGET_FILE:ogs> -r ${OgsTest_SOURCE_DIR}
-                ${OgsTest_SOURCE_DIR}/${OgsTest_NAME}
+        NAME ${TEST_NAME}
+        COMMAND
+            ${CMAKE_COMMAND} -DEXECUTABLE=$<TARGET_FILE:ogs>
+            "-DEXECUTABLE_ARGS=${_exe_args}"
+            "-DWRAPPER_COMMAND=${OgsTest_WRAPPER}"
+            -DWORKING_DIRECTORY=${OgsTest_BINARY_DIR}
+            -DLOG_FILE=${PROJECT_BINARY_DIR}/logs/${TEST_NAME_UNDERSCORE}.log
+            -P ${PROJECT_SOURCE_DIR}/scripts/cmake/test/OgsTestWrapper.cmake
     )
+
     # For debugging: message("Adding test with NAME ${TEST_NAME}
     # WORKING_DIRECTORY ${OgsTest_BINARY_DIR} COMMAND ${OgsTest_WRAPPER}
     # $<TARGET_FILE:ogs> -r ${OgsTest_SOURCE_DIR}
@@ -69,15 +79,18 @@ function(OgsTest)
         list(APPEND labels large)
     endif()
 
-    set_tests_properties(${TEST_NAME}
-        PROPERTIES
-            ENVIRONMENT VTKDIFF_EXE=$<TARGET_FILE:vtkdiff>
-            COST ${OgsTest_RUNTIME}
-            DISABLED ${OgsTest_DISABLED}
-            LABELS "${labels}"
+    set_tests_properties(
+        ${TEST_NAME}
+        PROPERTIES ENVIRONMENT
+                   VTKDIFF_EXE=$<TARGET_FILE:vtkdiff>
+                   COST
+                   ${OgsTest_RUNTIME}
+                   DISABLED
+                   ${OgsTest_DISABLED}
+                   LABELS
+                   "${labels}"
     )
-    # Disabled for the moment, does not work with CI under load
-    # if(NOT OGS_COVERAGE)
-    #     set_tests_properties(${TEST_NAME} PROPERTIES TIMEOUT ${timeout})
-    # endif()
+    # Disabled for the moment, does not work with CI under load if(NOT
+    # OGS_COVERAGE) set_tests_properties(${TEST_NAME} PROPERTIES TIMEOUT
+    # ${timeout}) endif()
 endfunction()
diff --git a/scripts/cmake/test/OgsTestWrapper.cmake b/scripts/cmake/test/OgsTestWrapper.cmake
new file mode 100644
index 0000000000000000000000000000000000000000..a90dbea0810619197147f300d0979a6548d308ca
--- /dev/null
+++ b/scripts/cmake/test/OgsTestWrapper.cmake
@@ -0,0 +1,11 @@
+execute_process(
+    COMMAND ${WRAPPER_COMMAND} ${EXECUTABLE} ${EXECUTABLE_ARGS}
+    WORKING_DIRECTORY ${WORKING_DIRECTORY}
+    RESULT_VARIABLE EXIT_CODE
+    OUTPUT_FILE ${LOG_FILE}
+    ERROR_FILE ${LOG_FILE}
+)
+
+if(NOT EXIT_CODE STREQUAL "0")
+    message(FATAL_ERROR "Exit code: ${EXIT_CODE}; log file: ${LOG_FILE}")
+endif()