diff --git a/cmake/modules/DuneMacros.cmake b/cmake/modules/DuneMacros.cmake
index b5d8752aefdcf0ceffa6ee87924364fe6ac2eca3..9d9221c84c80a8dcb4434d31440c405e809a5b45 100644
--- a/cmake/modules/DuneMacros.cmake
+++ b/cmake/modules/DuneMacros.cmake
@@ -882,7 +882,9 @@ endif()
     configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
   endif("${ARGC}" EQUAL "1")
 
-  test_dep()
+  if(NOT DUNE_DISABLE_TEST_MAGIC)
+    test_dep()
+  endif()
 
   include(CPack)
 
diff --git a/cmake/modules/DuneTestMacros.cmake b/cmake/modules/DuneTestMacros.cmake
index 3b5331718323c894c1cc642c611d200eedd79ac8..7cea1645c6ad9822bc3b1393056862f766b50e4c 100644
--- a/cmake/modules/DuneTestMacros.cmake
+++ b/cmake/modules/DuneTestMacros.cmake
@@ -47,8 +47,10 @@ endmacro(get_directory_test_target _target _dir)
 # E.g. for dune/istl/test the target will be dune_istl_test.
 #
 macro(add_directory_test_target _target)
-  get_directory_test_target(${_target} "${CMAKE_CURRENT_BINARY_DIR}")
-  add_custom_target(${${_target}})
-  dune_common_script_dir(SCRIPT_DIR)
-  configure_file(${SCRIPT_DIR}/BuildTests.cmake.in BuildTests.cmake @ONLY)
+  if(NOT DUNE_DISABLE_TEST_MAGIC)
+    get_directory_test_target(${_target} "${CMAKE_CURRENT_BINARY_DIR}")
+    add_custom_target(${${_target}})
+    dune_common_script_dir(SCRIPT_DIR)
+    configure_file(${SCRIPT_DIR}/BuildTests.cmake.in BuildTests.cmake @ONLY)
+  endif()
 endmacro(add_directory_test_target)