From f4498332f432b98a67a158dc6784f308d1cec07e Mon Sep 17 00:00:00 2001
From: Christoph Grueninger <christoph.grueninger@iws.uni-stuttgart.de>
Date: Mon, 23 Sep 2013 08:54:00 +0000
Subject: [PATCH] [CMake] Build test in make dependant if according parameter
 is set.

Tests are still built only for ctest calls, not for plain make.
Tests are built for make if -DDUMUX_BUILD_ALL_TESTS:BOOL=TRUE is set.
This change is needed for CDash, otherwise compile errors and warnings
where not displayed.

(reviewed by bernd)


git-svn-id: svn://svn.iws.uni-stuttgart.de/DUMUX/dumux/trunk@11537 2fb0f335-1f38-0410-981e-8018bf24f1b0
---
 cmake/modules/DumuxMacros.cmake              |  6 ++-
 cmake/modules/DumuxTestMacros.cmake          | 46 +++++++++++++++++
 test/common/generalproblem/CMakeLists.txt    | 22 +--------
 test/common/propertysystem/CMakeLists.txt    | 17 +------
 test/common/spline/CMakeLists.txt            | 18 +------
 test/decoupled/1p/CMakeLists.txt             | 31 ++----------
 test/decoupled/2p/CMakeLists.txt             | 52 ++++++--------------
 test/decoupled/2p2c/CMakeLists.txt           | 29 ++---------
 test/freeflow/navierstokes/CMakeLists.txt    | 24 ++-------
 test/freeflow/stokes/CMakeLists.txt          | 20 +-------
 test/freeflow/stokes2c/CMakeLists.txt        | 20 +-------
 test/freeflow/stokes2cni/CMakeLists.txt      | 20 +-------
 test/implicit/1p/CMakeLists.txt              | 33 ++-----------
 test/implicit/1p2c/CMakeLists.txt            | 22 +--------
 test/implicit/2p/CMakeLists.txt              | 23 +--------
 test/implicit/2p2c/CMakeLists.txt            | 23 +--------
 test/implicit/2p2cni/CMakeLists.txt          | 25 ++--------
 test/implicit/2pdfm/CMakeLists.txt           | 19 +------
 test/implicit/2pni/CMakeLists.txt            | 22 +--------
 test/implicit/3p/CMakeLists.txt              | 23 +--------
 test/implicit/3p3c/CMakeLists.txt            | 23 +--------
 test/implicit/3p3cni/CMakeLists.txt          | 22 +--------
 test/implicit/co2/CMakeLists.txt             | 25 ++--------
 test/implicit/co2ni/CMakeLists.txt           | 26 ++--------
 test/implicit/mpnc/CMakeLists.txt            | 39 +++------------
 test/implicit/richards/CMakeLists.txt        | 26 ++--------
 test/material/fluidsystems/CMakeLists.txt    | 17 +------
 test/material/immiscibleflash/CMakeLists.txt | 17 +------
 test/material/ncpflash/CMakeLists.txt        | 17 +------
 test/material/pengrobinson/CMakeLists.txt    | 17 +------
 test/material/tabulation/CMakeLists.txt      | 17 +------
 31 files changed, 136 insertions(+), 605 deletions(-)
 create mode 100644 cmake/modules/DumuxTestMacros.cmake

diff --git a/cmake/modules/DumuxMacros.cmake b/cmake/modules/DumuxMacros.cmake
index acc9dfaff4..e4bd218195 100644
--- a/cmake/modules/DumuxMacros.cmake
+++ b/cmake/modules/DumuxMacros.cmake
@@ -1,4 +1,6 @@
-
+# checks
 include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/CheckAlwaysInline.cmake)
 include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/CheckConstexpr.cmake)
-include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/CheckPatchedPDELab.cmake)
\ No newline at end of file
+include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/CheckPatchedPDELab.cmake)
+# additional macros
+include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/DumuxTestMacros.cmake)
diff --git a/cmake/modules/DumuxTestMacros.cmake b/cmake/modules/DumuxTestMacros.cmake
new file mode 100644
index 0000000000..aaf6e745e4
--- /dev/null
+++ b/cmake/modules/DumuxTestMacros.cmake
@@ -0,0 +1,46 @@
+###
+# Add a test. All necessary calls to dune CMake macros for adding a
+# test are called from this macro.
+# The added test is automatically build if cmake is invode with the command
+# line argument -DDUMUX_BUILD_ALL_TESTS:BOOL=TRUE otherwise the test is
+# built only when "ctest" / "make test" is invoked.
+# The test is only built if it does not already exist.
+#
+# Arguments:
+# - dumux_test:                   name of the new test
+# - dumux_test_executable:        name of the executable required by the test
+# - dumux_test_executable_source: source file (.cc) of the new test
+# - further arguments:            are optional and are used as arguments for calling the test
+###
+macro(add_dumux_test dumux_test dumux_test_executable dumux_test_executable_source)
+  # create test target for directory, but only if not yet created
+  get_directory_test_target(potential_test_target "${CMAKE_CURRENT_BINARY_DIR}")
+  if(NOT TARGET ${potential_test_target})
+    add_directory_test_target(_test_target)
+    set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+      PROPERTY TEST_INCLUDE_FILE ${CMAKE_CURRENT_BINARY_DIR}/BuildTests.cmake)
+  endif(NOT TARGET ${potential_test_target})
+
+  # add executable
+  # check whether executable already exists
+  if(NOT TARGET ${dumux_test_executable})
+    #set property whether it has to be built with make or only with make test
+    if(${DUMUX_BUILD_ALL_TESTS})
+      add_executable(${dumux_test_executable} ${dumux_test_executable_source})
+    else()
+      add_executable(${dumux_test_executable} EXCLUDE_FROM_ALL ${dumux_test_executable_source})
+    endif(${DUMUX_BUILD_ALL_TESTS})
+  endif(NOT TARGET ${dumux_test_executable})
+
+  # link all libraries to executable
+  target_link_libraries(${dumux_test_executable} ${DUNE_LIBS})
+
+  # get optional arguments
+  # cannot use ARGN directly with list() command, copy to a variable first
+  set(dumux_test_args ${ARGN})
+  list(LENGTH dumux_test_args num_dumux_test_args)
+
+  # add test
+  add_test(${dumux_test} ${dumux_test_args})
+  add_dependencies(${_test_target} ${dumux_test})
+endmacro(add_dumux_test)
diff --git a/test/common/generalproblem/CMakeLists.txt b/test/common/generalproblem/CMakeLists.txt
index 9837abcada..07b3607d83 100644
--- a/test/common/generalproblem/CMakeLists.txt
+++ b/test/common/generalproblem/CMakeLists.txt
@@ -1,8 +1,4 @@
-# build target for the simple twophase lens problem in a general
-# definition for both box and decoupled model
-add_executable("test_generalproblem2p" EXCLUDE_FROM_ALL test_generalproblem2p.cc)
-
-add_test(test_general_box
+add_dumux_test(test_general_box test_generalproblem2p test_generalproblem2p.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/generallens_box-reference.vtu
@@ -13,7 +9,7 @@ add_test(test_general_box
   -TimeManager.TEnd 1e2
   -TimeManager.DtInitial 2e1)
 
-add_test(test_general_dec
+add_dumux_test(test_general_dec test_generalproblem2p test_generalproblem2p.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/generallens_decoupled-reference.vtu
@@ -24,17 +20,3 @@ add_test(test_general_dec
   -TimeManager.TEnd 1e2
   -TimeManager.DtInitial 2e1)
 
-set(NORMALTESTS
-  test_generalproblem2p)
-set(ALLTESTS ${NORMALTESTS})
-
-# We do not want want to build the tests during make all,
-# but just build them on demand
-add_directory_test_target(_test_target)
-add_dependencies(${_test_target} ${ALLTESTS})
-set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-  PROPERTY TEST_INCLUDE_FILE ${CMAKE_CURRENT_BINARY_DIR}/BuildTests.cmake)
-
-foreach(_exe ${ALLTESTS})
-  target_link_libraries(${_exe} ${DUNE_LIBS})
-endforeach(_exe ${ALLTESTS})
diff --git a/test/common/propertysystem/CMakeLists.txt b/test/common/propertysystem/CMakeLists.txt
index 54929f7be4..23e495c47a 100644
--- a/test/common/propertysystem/CMakeLists.txt
+++ b/test/common/propertysystem/CMakeLists.txt
@@ -1,18 +1,3 @@
 # build the test for the property system
-add_executable("test_propertysystem" EXCLUDE_FROM_ALL test_propertysystem.cc)
-add_test(test_propertysystem
+add_dumux_test(test_propertysystem test_propertysystem test_propertysystem.cc
   ${CMAKE_CURRENT_BINARY_DIR}/test_propertysystem)
-
-set(NORMALTESTS test_propertysystem)
-set(ALLTESTS ${NORMALTESTS})
-
-# We do not want want to build the tests during make all,
-# but just build them on demand
-add_directory_test_target(_test_target)
-add_dependencies(${_test_target} ${ALLTESTS})
-set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-  PROPERTY TEST_INCLUDE_FILE ${CMAKE_CURRENT_BINARY_DIR}/BuildTests.cmake)
-
-foreach(_exe ${ALLTESTS})
-  target_link_libraries(${_exe} ${DUNE_LIBS})
-endforeach(_exe ${ALLTESTS})
\ No newline at end of file
diff --git a/test/common/spline/CMakeLists.txt b/test/common/spline/CMakeLists.txt
index 7f7ef3aee9..bb6988dc82 100644
--- a/test/common/spline/CMakeLists.txt
+++ b/test/common/spline/CMakeLists.txt
@@ -1,18 +1,2 @@
-# add build targets
-add_executable("test_spline" EXCLUDE_FROM_ALL test_spline.cc)
-add_test(test_spline
+add_dumux_test(test_spline test_spline test_spline.cc
   ${CMAKE_CURRENT_BINARY_DIR}/test_spline)
-
-set(NORMALTESTS test_spline)
-set(ALLTESTS ${NORMALTESTS})
-
-# We do not want want to build the tests during make all,
-# but just build them on demand
-add_directory_test_target(_test_target)
-add_dependencies(${_test_target} ${ALLTESTS})
-set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-  PROPERTY TEST_INCLUDE_FILE ${CMAKE_CURRENT_BINARY_DIR}/BuildTests.cmake)
-
-foreach(_exe ${ALLTESTS})
-  target_link_libraries(${_exe} ${DUNE_LIBS})
-endforeach(_exe ${ALLTESTS})
diff --git a/test/decoupled/1p/CMakeLists.txt b/test/decoupled/1p/CMakeLists.txt
index c0e5302a49..ea3968eefc 100644
--- a/test/decoupled/1p/CMakeLists.txt
+++ b/test/decoupled/1p/CMakeLists.txt
@@ -1,6 +1,4 @@
-# add build targets
-add_executable("test_dec1p" EXCLUDE_FROM_ALL test_1p.cc)
-add_test(test_dec1p
+add_dumux_test(test_dec1p test_dec1p test_1p.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/test_1p-reference.vtu
@@ -8,8 +6,7 @@ add_test(test_dec1p
   ${CMAKE_CURRENT_BINARY_DIR}/test_dec1p
   -ParameterFile ${CMAKE_CURRENT_SOURCE_DIR}/test_1p.input)
 
-add_executable("test_diffusion" EXCLUDE_FROM_ALL test_diffusion.cc)
-add_test(test_diffusion
+add_dumux_test(test_diffusion test_diffusion test_diffusion.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/diffusion-reference.vtu
@@ -17,10 +14,7 @@ add_test(test_diffusion
   ${CMAKE_CURRENT_BINARY_DIR}/test_diffusion
   3)
 
-add_executable("test_diffusion3d" EXCLUDE_FROM_ALL test_diffusion3d.cc)
-add_dune_alugrid_flags(test_diffusion3d)
-add_dune_ug_flags(test_diffusion3d)
-add_test(test_diffusion3d
+add_dumux_test(test_diffusion3d test_diffusion3d test_diffusion3d.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/test_diffusion3d-reference.vtu
@@ -28,20 +22,5 @@ add_test(test_diffusion3d
   ${CMAKE_CURRENT_BINARY_DIR}/test_diffusion3d
   -ParameterFile ${CMAKE_CURRENT_SOURCE_DIR}/test_diffusion3d.input
   -Grid.File ${CMAKE_CURRENT_SOURCE_DIR}/grids/test_diffusion3d_ug1.dgf)
-
-set(NORMALTESTS
-  test_dec1p
-  test_diffusion
-  test_diffusion3d)
-set(ALLTESTS ${NORMALTESTS})
-
-# We do not want want to build the tests during make all,
-# but just build them on demand
-add_directory_test_target(_test_target)
-add_dependencies(${_test_target} ${ALLTESTS})
-set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-  PROPERTY TEST_INCLUDE_FILE ${CMAKE_CURRENT_BINARY_DIR}/BuildTests.cmake)
-
-foreach(_exe ${ALLTESTS})
-  target_link_libraries(${_exe} ${DUNE_LIBS})
-endforeach(_exe ${ALLTESTS})
+add_dune_alugrid_flags(test_diffusion3d)
+add_dune_ug_flags(test_diffusion3d)
diff --git a/test/decoupled/2p/CMakeLists.txt b/test/decoupled/2p/CMakeLists.txt
index 5d2968721b..26d2e55f3e 100644
--- a/test/decoupled/2p/CMakeLists.txt
+++ b/test/decoupled/2p/CMakeLists.txt
@@ -1,6 +1,4 @@
-# add build targets
-add_executable("test_impes" EXCLUDE_FROM_ALL test_impes.cc)
-add_test(test_impes
+add_dumux_test(test_impes test_impes test_impes.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/test_impes-reference.vtu
@@ -8,21 +6,18 @@ add_test(test_impes
   ${CMAKE_CURRENT_BINARY_DIR}/test_impes
   -ParameterFile ${CMAKE_CURRENT_SOURCE_DIR}/test_impes.input)
 
-add_executable("test_impesadaptive" EXCLUDE_FROM_ALL test_impesadaptive.cc)
-add_dune_alugrid_flags(test_impesadaptive)
-add_test(test_impesadaptive
+add_dumux_test(test_impesadaptive test_impesadaptive test_impesadaptive.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/test_2padaptive-reference.vtu
   ${CMAKE_CURRENT_BINARY_DIR}/test_2padaptive-00007.vtu
   ${CMAKE_CURRENT_BINARY_DIR}/test_impesadaptive
   -ParameterFile ${CMAKE_CURRENT_SOURCE_DIR}/test_impesadaptive.input)
+add_dune_alugrid_flags(test_impesadaptive)
 
 add_executable("test_impeswithamg" EXCLUDE_FROM_ALL test_impeswithamg.cc)
 if(MPI_FOUND)
-  add_dune_superlu_flags(test_impeswithamg)
-  add_dune_mpi_flags(test_impeswithamg)
-  add_test(test_impeswithamg
+  add_dumux_test(test_impeswithamg test_impeswithamg test_impeswithamg.cc
     ${CMAKE_SOURCE_DIR}/bin/runTest.sh
     ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
     ${CMAKE_SOURCE_DIR}/test/references/test_impes-reference-parallel.vtu
@@ -31,8 +26,10 @@ if(MPI_FOUND)
     -ParameterFile ${CMAKE_CURRENT_SOURCE_DIR}/test_impeswithamg.input
     -Grid.File ${CMAKE_CURRENT_SOURCE_DIR}/grids/test_impeswithamg.dgf
     -TimeManager.TEnd 7e7)
-else(MPI_FOUND)
-  add_test(test_impeswithamg
+  add_dune_superlu_flags(test_impeswithamg)
+  add_dune_mpi_flags(test_impeswithamg)
+else()
+  add_dumux_test(test_impeswithamg test_impeswithamg test_impeswithamg.cc
     ${CMAKE_SOURCE_DIR}/bin/runTest.sh
     ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
     ${CMAKE_SOURCE_DIR}/test/references/test_impes-reference.vtu
@@ -42,8 +39,7 @@ else(MPI_FOUND)
     -Grid.File ${CMAKE_CURRENT_SOURCE_DIR}/grids/test_impeswithamg.dgf)
 endif(MPI_FOUND)
 
-add_executable("test_transport" EXCLUDE_FROM_ALL test_transport.cc)
-add_test(test_transport
+add_dumux_test(test_transport test_transport test_transport.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/test_transport-reference.vtu
@@ -52,10 +48,7 @@ add_test(test_transport
   -ParameterFile ${CMAKE_CURRENT_SOURCE_DIR}/test_transport.input
   -Grid.File ${CMAKE_CURRENT_SOURCE_DIR}/grids/test_transport.dgf)
 
-add_executable("test_mpfa2p" EXCLUDE_FROM_ALL test_mpfa2p.cc)
-add_dune_alugrid_flags(test_mpfa2p)
-add_dune_superlu_flags(test_mpfa2p)
-add_test(test_mpfao2p
+add_dumux_test(test_mpfao2p test_mpfa2p test_mpfa2p.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/test_mpfao2p-reference.vtu
@@ -63,7 +56,7 @@ add_test(test_mpfao2p
   ${CMAKE_CURRENT_BINARY_DIR}/test_mpfa2p
   -ParameterFile ${CMAKE_CURRENT_SOURCE_DIR}/test_mpfa2p.input
   -ModelType MPFAO)
-add_test(test_mpfal2p
+add_dumux_test(test_mpfal2p test_mpfa2p test_mpfa2p.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/test_mpfal2p-reference.vtu
@@ -71,7 +64,7 @@ add_test(test_mpfal2p
   ${CMAKE_CURRENT_BINARY_DIR}/test_mpfa2p
   -ParameterFile ${CMAKE_CURRENT_SOURCE_DIR}/test_mpfa2p.input
   -ModelType MPFAL)
-add_test(test_mpfal2padaptive
+add_dumux_test(test_mpfal2padaptive test_mpfa2p test_mpfa2p.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/test_mpfal2padaptive-reference.vtu
@@ -79,22 +72,5 @@ add_test(test_mpfal2padaptive
   ${CMAKE_CURRENT_BINARY_DIR}/test_mpfa2p
   -ParameterFile ${CMAKE_CURRENT_SOURCE_DIR}/test_mpfa2p.input
   -ModelType MPFALAdaptive)
-
-set(NORMALTESTS
-  test_impes
-  test_impesadaptive
-  test_impeswithamg
-  test_transport
-  test_mpfa2p)
-set(ALLTESTS ${NORMALTESTS})
-
-# We do not want want to build the tests during make all,
-# but just build them on demand
-add_directory_test_target(_test_target)
-add_dependencies(${_test_target} ${ALLTESTS})
-set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-  PROPERTY TEST_INCLUDE_FILE ${CMAKE_CURRENT_BINARY_DIR}/BuildTests.cmake)
-
-foreach(_exe ${ALLTESTS})
-  target_link_libraries(${_exe} ${DUNE_LIBS})
-endforeach(_exe ${ALLTESTS})
+add_dune_alugrid_flags(test_mpfa2p)
+add_dune_superlu_flags(test_mpfa2p)
diff --git a/test/decoupled/2p2c/CMakeLists.txt b/test/decoupled/2p2c/CMakeLists.txt
index 268656086b..9d3b284ecd 100644
--- a/test/decoupled/2p2c/CMakeLists.txt
+++ b/test/decoupled/2p2c/CMakeLists.txt
@@ -1,16 +1,13 @@
-# add build targets
-add_executable("test_adaptive2p2c" EXCLUDE_FROM_ALL test_adaptive2p2c.cc)
-add_dune_alugrid_flags(test_adaptive2p2c)
-add_test(test_adaptive2p2c
+add_dumux_test(test_adaptive2p2c test_adaptive2p2c test_adaptive2p2c.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/test_adaptive2p2c-reference.vtu
   ${CMAKE_CURRENT_BINARY_DIR}/test_adaptive2p2c-00008.vtu
   ${CMAKE_CURRENT_BINARY_DIR}/test_adaptive2p2c
   -ParameterFile ${CMAKE_CURRENT_SOURCE_DIR}/test_adaptive2p2c.input)
+add_dune_alugrid_flags(test_adaptive2p2c)
 
-add_executable("test_dec2p2c" EXCLUDE_FROM_ALL test_dec2p2c.cc)
-add_test(test_dec2p2c
+add_dumux_test(test_dec2p2c test_dec2p2c test_dec2p2c.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/test_dec2p2c-reference.vtu
@@ -18,27 +15,9 @@ add_test(test_dec2p2c
   ${CMAKE_CURRENT_BINARY_DIR}/test_dec2p2c
   -ParameterFile ${CMAKE_CURRENT_SOURCE_DIR}/test_dec2p2c.input)
 
-add_executable("test_multiphysics2p2c" EXCLUDE_FROM_ALL test_multiphysics2p2c.cc)
-add_test(test_multiphysics2p2c
+add_dumux_test(test_multiphysics2p2c test_multiphysics2p2c test_multiphysics2p2c.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/test_multiphysics2p2c-reference.vtu
   ${CMAKE_CURRENT_BINARY_DIR}/test_multiphysics2p2c-00021.vtu
   ${CMAKE_CURRENT_BINARY_DIR}/test_multiphysics2p2c)
-
-set(NORMALTESTS
-  test_adaptive2p2c
-  test_dec2p2c
-  test_multiphysics2p2c)
-set(ALLTESTS ${NORMALTESTS})
-
-# We do not want want to build the tests during make all,
-# but just build them on demand
-add_directory_test_target(_test_target)
-add_dependencies(${_test_target} ${ALLTESTS})
-set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-  PROPERTY TEST_INCLUDE_FILE ${CMAKE_CURRENT_BINARY_DIR}/BuildTests.cmake)
-
-foreach(_exe ${ALLTESTS})
-  target_link_libraries(${_exe} ${DUNE_LIBS})
-endforeach(_exe ${ALLTESTS})
diff --git a/test/freeflow/navierstokes/CMakeLists.txt b/test/freeflow/navierstokes/CMakeLists.txt
index 778973bc90..012a21ae9d 100644
--- a/test/freeflow/navierstokes/CMakeLists.txt
+++ b/test/freeflow/navierstokes/CMakeLists.txt
@@ -1,9 +1,4 @@
-# add build targets
-add_executable("test_navierstokes" EXCLUDE_FROM_ALL test_navierstokes.cc)
-add_dune_superlu_flags(test_navierstokes)
-add_dune_alugrid_flags(test_navierstokes)
-add_dune_ug_flags(test_navierstokes)
-add_test(test_navierstokes
+add_dumux_test(test_navierstokes test_navierstokes test_navierstokes.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/navierstokes-reference.vtu
@@ -11,17 +6,6 @@ add_test(test_navierstokes
   ${CMAKE_CURRENT_BINARY_DIR}/test_navierstokes
   -ParameterFile ${CMAKE_CURRENT_SOURCE_DIR}/test_navierstokes.input
   -Grid.File ${CMAKE_CURRENT_SOURCE_DIR}/grids/test_navierstokes.dgf)
-
-set(NORMALTESTS test_navierstokes)
-set(ALLTESTS ${NORMALTESTS})
-
-# We do not want want to build the tests during make all,
-# but just build them on demand
-add_directory_test_target(_test_target)
-add_dependencies(${_test_target} ${ALLTESTS})
-set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-  PROPERTY TEST_INCLUDE_FILE ${CMAKE_CURRENT_BINARY_DIR}/BuildTests.cmake)
-
-foreach(_exe ${ALLTESTS})
-  target_link_libraries(${_exe} ${DUNE_LIBS})
-endforeach(_exe ${ALLTESTS})
+add_dune_superlu_flags(test_navierstokes)
+add_dune_alugrid_flags(test_navierstokes)
+add_dune_ug_flags(test_navierstokes)
diff --git a/test/freeflow/stokes/CMakeLists.txt b/test/freeflow/stokes/CMakeLists.txt
index 58d0d54f49..d6e06a117f 100644
--- a/test/freeflow/stokes/CMakeLists.txt
+++ b/test/freeflow/stokes/CMakeLists.txt
@@ -1,7 +1,4 @@
-# add build targets
-add_executable("test_stokes" EXCLUDE_FROM_ALL test_stokes.cc)
-add_dune_superlu_flags(test_stokes)
-add_test(test_stokes
+add_dumux_test(test_stokes test_stokes test_stokes.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/stokes-reference.vtu
@@ -9,17 +6,4 @@ add_test(test_stokes
   ${CMAKE_CURRENT_BINARY_DIR}/test_stokes
   -ParameterFile ${CMAKE_CURRENT_SOURCE_DIR}/test_stokes.input
   -Grid.File ${CMAKE_CURRENT_SOURCE_DIR}/grids/test_stokes.dgf)
-
-set(NORMALTESTS test_stokes)
-set(ALLTESTS ${NORMALTESTS})
-
-# We do not want want to build the tests during make all,
-# but just build them on demand
-add_directory_test_target(_test_target)
-add_dependencies(${_test_target} ${ALLTESTS})
-set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-  PROPERTY TEST_INCLUDE_FILE ${CMAKE_CURRENT_BINARY_DIR}/BuildTests.cmake)
-
-foreach(_exe ${ALLTESTS})
-  target_link_libraries(${_exe} ${DUNE_LIBS})
-endforeach(_exe ${ALLTESTS})
+add_dune_superlu_flags(test_stokes)
diff --git a/test/freeflow/stokes2c/CMakeLists.txt b/test/freeflow/stokes2c/CMakeLists.txt
index baca022945..fd2fc85318 100644
--- a/test/freeflow/stokes2c/CMakeLists.txt
+++ b/test/freeflow/stokes2c/CMakeLists.txt
@@ -1,7 +1,4 @@
-# add build targets
-add_executable("test_stokes2c" EXCLUDE_FROM_ALL test_stokes2c.cc)
-add_dune_superlu_flags(test_stokes2c)
-add_test(test_stokes
+add_dumux_test(test_stokes2c test_stokes2c test_stokes2c.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/stokes2c-reference.vtu
@@ -9,17 +6,4 @@ add_test(test_stokes
   ${CMAKE_CURRENT_BINARY_DIR}/test_stokes2c
   -ParameterFile ${CMAKE_CURRENT_SOURCE_DIR}/test_stokes2c.input
   -Grid.File ${CMAKE_CURRENT_SOURCE_DIR}/grids/test_stokes2c.dgf)
-
-set(NORMALTESTS test_stokes2c)
-set(ALLTESTS ${NORMALTESTS})
-
-# We do not want want to build the tests during make all,
-# but just build them on demand
-add_directory_test_target(_test_target)
-add_dependencies(${_test_target} ${ALLTESTS})
-set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-  PROPERTY TEST_INCLUDE_FILE ${CMAKE_CURRENT_BINARY_DIR}/BuildTests.cmake)
-
-foreach(_exe ${ALLTESTS})
-  target_link_libraries(${_exe} ${DUNE_LIBS})
-endforeach(_exe ${ALLTESTS})
+add_dune_superlu_flags(test_stokes2c)
diff --git a/test/freeflow/stokes2cni/CMakeLists.txt b/test/freeflow/stokes2cni/CMakeLists.txt
index 989106ba57..6997547274 100644
--- a/test/freeflow/stokes2cni/CMakeLists.txt
+++ b/test/freeflow/stokes2cni/CMakeLists.txt
@@ -1,7 +1,4 @@
-# add build targets
-add_executable("test_stokes2cni" EXCLUDE_FROM_ALL test_stokes2cni.cc)
-add_dune_superlu_flags(test_stokes2cni)
-add_test(test_stokes
+add_dumux_test(test_stokes2cni test_stokes2cni test_stokes2cni.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/stokes2cni-reference.vtu
@@ -9,17 +6,4 @@ add_test(test_stokes
   ${CMAKE_CURRENT_BINARY_DIR}/test_stokes2cni
   -ParameterFile ${CMAKE_CURRENT_SOURCE_DIR}/test_stokes2cni.input
   -Grid.File ${CMAKE_CURRENT_SOURCE_DIR}/grids/test_stokes2cni.dgf)
-
-set(NORMALTESTS test_stokes2cni)
-set(ALLTESTS ${NORMALTESTS})
-
-# We do not want want to build the tests during make all,
-# but just build them on demand
-add_directory_test_target(_test_target)
-add_dependencies(${_test_target} ${ALLTESTS})
-set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-  PROPERTY TEST_INCLUDE_FILE ${CMAKE_CURRENT_BINARY_DIR}/BuildTests.cmake)
-
-foreach(_exe ${ALLTESTS})
-  target_link_libraries(${_exe} ${DUNE_LIBS})
-endforeach(_exe ${ALLTESTS})
+add_dune_superlu_flags(test_stokes2cni)
diff --git a/test/implicit/1p/CMakeLists.txt b/test/implicit/1p/CMakeLists.txt
index 56a1ae35cd..e9b26256a3 100644
--- a/test/implicit/1p/CMakeLists.txt
+++ b/test/implicit/1p/CMakeLists.txt
@@ -1,18 +1,15 @@
-# build target for the onephase-onecomponent test problem
-add_executable("test_box1p" EXCLUDE_FROM_ALL test_box1p.cc)
-add_test(test_box1p
+add_dumux_test(test_box1p test_box1p test_box1p.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/1ptestbox-reference.vtu
   ${CMAKE_CURRENT_BINARY_DIR}/1ptestbox-00002.vtu
   ${CMAKE_CURRENT_BINARY_DIR}/test_box1p
   -ParameterFile ${CMAKE_CURRENT_SOURCE_DIR}/test_box1p.input
-  -Grid.File ${CMAKE_CURRENT_SOURCE_DIR}/grids/test_1p_2d.dgf               
+  -Grid.File ${CMAKE_CURRENT_SOURCE_DIR}/grids/test_1p_2d.dgf
   -TimeManager.TEnd 1
   -TimeManager.DtInitial 1)
 
-add_executable("test_box1pwithamg" EXCLUDE_FROM_ALL test_box1pwithamg.cc)
-add_test(test_box1pwithamg
+add_dumux_test(test_box1pwithamg test_box1pwithamg test_box1pwithamg.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/1ptestbox-reference.vtu
@@ -23,8 +20,7 @@ add_test(test_box1pwithamg
   -TimeManager.TEnd 1
   -TimeManager.DtInitial 1)
 
-add_executable("test_cc1p" EXCLUDE_FROM_ALL test_cc1p.cc)
-add_test(test_cc1p
+add_dumux_test(test_cc1p test_cc1p test_cc1p.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/1ptestcc-reference.vtu
@@ -35,8 +31,7 @@ add_test(test_cc1p
   -TimeManager.TEnd 1
   -TimeManager.DtInitial 1)
 
-add_executable("test_cc1pwithamg" EXCLUDE_FROM_ALL test_cc1pwithamg.cc)
-add_test(test_cc1pwithamg
+add_dumux_test(test_cc1pwithamg test_cc1pwithamg test_cc1pwithamg.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/1ptestcc-reference.vtu
@@ -46,21 +41,3 @@ add_test(test_cc1pwithamg
   -Grid.File ${CMAKE_CURRENT_SOURCE_DIR}/grids/test_1p_2d.dgf
   -TimeManager.TEnd 1
   -TimeManager.DtInitial 1)
-
-set(NORMALTESTS
-  test_box1p
-  test_box1pwithamg
-  test_cc1p
-  test_cc1pwithamg)
-set(ALLTESTS ${NORMALTESTS})
-
-# We do not want want to build the tests during make all,
-# but just build them on demand
-add_directory_test_target(_test_target)
-add_dependencies(${_test_target} ${ALLTESTS})
-set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-  PROPERTY TEST_INCLUDE_FILE ${CMAKE_CURRENT_BINARY_DIR}/BuildTests.cmake)
-
-foreach(_exe ${ALLTESTS})
-  target_link_libraries(${_exe} ${DUNE_LIBS})
-endforeach(_exe ${ALLTESTS})
diff --git a/test/implicit/1p2c/CMakeLists.txt b/test/implicit/1p2c/CMakeLists.txt
index 2b54d8125c..12627ddf7d 100644
--- a/test/implicit/1p2c/CMakeLists.txt
+++ b/test/implicit/1p2c/CMakeLists.txt
@@ -1,5 +1,4 @@
-add_executable("test_box1p2c" EXCLUDE_FROM_ALL test_box1p2c.cc)
-add_test(test_box1p2c
+add_dumux_test(test_box1p2c test_box1p2c test_box1p2c.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/outflowbox-reference.vtu
@@ -10,8 +9,7 @@ add_test(test_box1p2c
   -TimeManager.TEnd 100
   -TimeManager.DtInitial 1)
 
-add_executable("test_cc1p2c" EXCLUDE_FROM_ALL test_cc1p2c.cc)
-add_test(test_cc1p2c
+add_dumux_test(test_cc1p2c test_cc1p2c test_cc1p2c.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/outflowcc-reference.vtu
@@ -21,19 +19,3 @@ add_test(test_cc1p2c
   -Grid.File ${CMAKE_CURRENT_SOURCE_DIR}/grids/test_1p2c.dgf
   -TimeManager.TEnd 100
   -TimeManager.DtInitial 1)
-
-set(NORMALTESTS
-  test_box1p2c
-  test_cc1p2c)
-set(ALLTESTS ${NORMALTESTS})
-
-# We do not want want to build the tests during make all,
-# but just build them on demand
-add_directory_test_target(_test_target)
-add_dependencies(${_test_target} ${ALLTESTS})
-set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-  PROPERTY TEST_INCLUDE_FILE ${CMAKE_CURRENT_BINARY_DIR}/BuildTests.cmake)
-
-foreach(_exe ${ALLTESTS})
-  target_link_libraries(${_exe} ${DUNE_LIBS})
-endforeach(_exe ${ALLTESTS})
diff --git a/test/implicit/2p/CMakeLists.txt b/test/implicit/2p/CMakeLists.txt
index fefa3b4428..e276b98ac9 100644
--- a/test/implicit/2p/CMakeLists.txt
+++ b/test/implicit/2p/CMakeLists.txt
@@ -1,6 +1,4 @@
-# build target for the simple twophase lens problem
-add_executable("test_box2p" EXCLUDE_FROM_ALL test_box2p.cc)
-add_test(test_box2p
+add_dumux_test(test_box2p test_box2p test_box2p.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/lensbox-reference.vtu
@@ -11,8 +9,7 @@ add_test(test_box2p
   -TimeManager.TEnd 3000
   -TimeManager.DtInitial 250)
 
-add_executable("test_cc2p" EXCLUDE_FROM_ALL test_cc2p.cc)
-add_test(test_cc2p
+add_dumux_test(test_cc2p test_cc2p test_cc2p.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/lenscc-reference.vtu
@@ -22,19 +19,3 @@ add_test(test_cc2p
   -Grid.File ${CMAKE_CURRENT_SOURCE_DIR}/grids/test_2p.dgf
   -TimeManager.TEnd 3000
   -TimeManager.DtInitial 250)
-
-set(NORMALTESTS
-  test_box2p
-  test_cc2p)
-set(ALLTESTS ${NORMALTESTS})
-
-# We do not want want to build the tests during make all,
-# but just build them on demand
-add_directory_test_target(_test_target)
-add_dependencies(${_test_target} ${ALLTESTS})
-set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-  PROPERTY TEST_INCLUDE_FILE ${CMAKE_CURRENT_BINARY_DIR}/BuildTests.cmake)
-
-foreach(_exe ${ALLTESTS})
-  target_link_libraries(${_exe} ${DUNE_LIBS})
-endforeach(_exe ${ALLTESTS})
diff --git a/test/implicit/2p2c/CMakeLists.txt b/test/implicit/2p2c/CMakeLists.txt
index 0692e3337f..f7c736e60c 100644
--- a/test/implicit/2p2c/CMakeLists.txt
+++ b/test/implicit/2p2c/CMakeLists.txt
@@ -1,6 +1,4 @@
-# build target for the twophase-twocomponent test problem
-add_executable("test_box2p2c" EXCLUDE_FROM_ALL test_box2p2c.cc)
-add_test(test_box2p2c
+add_dumux_test(test_box2p2c test_box2p2c test_box2p2c.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/injectionbox-reference.vtu
@@ -11,8 +9,7 @@ add_test(test_box2p2c
   -TimeManager.TEnd 1e4
   -TimeManager.DtInitial 250)
 
-add_executable("test_cc2p2c" EXCLUDE_FROM_ALL test_cc2p2c.cc)
-add_test(test_cc2p2c
+add_dumux_test(test_cc2p2c test_cc2p2c test_cc2p2c.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/injectioncc-reference.vtu
@@ -22,19 +19,3 @@ add_test(test_cc2p2c
   -Grid.File ${CMAKE_CURRENT_SOURCE_DIR}/grids/test_2p2c.dgf
   -TimeManager.TEnd 1e4
   -TimeManager.DtInitial 250)
-
-set(NORMALTESTS
-  test_box2p2c
-  test_cc2p2c)
-set(ALLTESTS ${NORMALTESTS})
-
-# We do not want want to build the tests during make all,
-# but just build them on demand
-add_directory_test_target(_test_target)
-add_dependencies(${_test_target} ${ALLTESTS})
-set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-  PROPERTY TEST_INCLUDE_FILE ${CMAKE_CURRENT_BINARY_DIR}/BuildTests.cmake)
-
-foreach(_exe ${ALLTESTS})
-  target_link_libraries(${_exe} ${DUNE_LIBS})
-endforeach(_exe ${ALLTESTS})
diff --git a/test/implicit/2p2cni/CMakeLists.txt b/test/implicit/2p2cni/CMakeLists.txt
index 37f4a957ab..58aa52cac0 100644
--- a/test/implicit/2p2cni/CMakeLists.txt
+++ b/test/implicit/2p2cni/CMakeLists.txt
@@ -1,6 +1,4 @@
-# build target for the 2p2cni test problem
-add_executable("test_box2p2cni" EXCLUDE_FROM_ALL test_box2p2cni.cc)
-add_test(test_box2p2cni
+add_dumux_test(test_box2p2cni test_box2p2cni test_box2p2cni.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/waterairbox-reference.vtu
@@ -11,8 +9,7 @@ add_test(test_box2p2cni
   -TimeManager.TEnd 1e4
   -TimeManager.DtInitial 250)
 
-add_executable("test_cc2p2cni" EXCLUDE_FROM_ALL test_cc2p2cni.cc)
-add_test(test_cc2p2cni
+add_dumux_test(test_cc2p2cni test_cc2p2cni test_cc2p2cni.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/wateraircc-reference.vtu
@@ -21,20 +18,4 @@ add_test(test_cc2p2cni
   -ParameterFile ${CMAKE_CURRENT_SOURCE_DIR}/test_cc2p2cni.input
   -Grid.File ${CMAKE_CURRENT_SOURCE_DIR}/grids/test_2p2cni.dgf
   -TimeManager.TEnd 1e4
-  -TimeManager.DtInitial 250)
-
-set(NORMALTESTS
-  test_box2p2cni
-  test_cc2p2cni)
-set(ALLTESTS ${NORMALTESTS})
-
-# We do not want want to build the tests during make all,
-# but just build them on demand
-add_directory_test_target(_test_target)
-add_dependencies(${_test_target} ${ALLTESTS})
-set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-  PROPERTY TEST_INCLUDE_FILE ${CMAKE_CURRENT_BINARY_DIR}/BuildTests.cmake)
-
-foreach(_exe ${ALLTESTS})
-  target_link_libraries(${_exe} ${DUNE_LIBS})
-endforeach(_exe ${ALLTESTS})
+  -TimeManager.DtInitial 250)
\ No newline at end of file
diff --git a/test/implicit/2pdfm/CMakeLists.txt b/test/implicit/2pdfm/CMakeLists.txt
index 337bf662ec..48b2499987 100644
--- a/test/implicit/2pdfm/CMakeLists.txt
+++ b/test/implicit/2pdfm/CMakeLists.txt
@@ -1,6 +1,4 @@
-add_executable("test_2pdfm" EXCLUDE_FROM_ALL test_2pdfm.cc)
-add_dune_ug_flags(test_2pdfm)
-add_test(test_2pdfm
+add_dumux_test(test_2pdfm test_2pdfm test_2pdfm.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/2pdfm-reference.vtu
@@ -8,17 +6,4 @@ add_test(test_2pdfm
   ${CMAKE_CURRENT_BINARY_DIR}/test_2pdfm
   -ParameterFile ${CMAKE_CURRENT_SOURCE_DIR}/test_2pdfm.input
   -Grid.File ${CMAKE_CURRENT_SOURCE_DIR}/grids/2pdfmartmesh.net)
-
-set(NORMALTESTS test_2pdfm)
-set(ALLTESTS ${NORMALTESTS})
-
-# We do not want want to build the tests during make all,
-# but just build them on demand
-add_directory_test_target(_test_target)
-add_dependencies(${_test_target} ${ALLTESTS})
-set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-  PROPERTY TEST_INCLUDE_FILE ${CMAKE_CURRENT_BINARY_DIR}/BuildTests.cmake)
-
-foreach(_exe ${ALLTESTS})
-  target_link_libraries(${_exe} ${DUNE_LIBS}  ${MPI_LIBRARIES})
-endforeach(_exe ${ALLTESTS})
+add_dune_ug_flags(test_2pdfm)
diff --git a/test/implicit/2pni/CMakeLists.txt b/test/implicit/2pni/CMakeLists.txt
index 046f83477b..e6d7022bc8 100644
--- a/test/implicit/2pni/CMakeLists.txt
+++ b/test/implicit/2pni/CMakeLists.txt
@@ -1,5 +1,4 @@
-add_executable("test_box2pni" EXCLUDE_FROM_ALL test_box2pni.cc)
-add_test(test_box2pni
+add_dumux_test(test_box2pni test_box2pni test_box2pni.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/injection2pnibox-reference.vtu
@@ -9,8 +8,7 @@ add_test(test_box2pni
   -TimeManager.TEnd 1e4
   -TimeManager.DtInitial 250)
 
-add_executable("test_cc2pni" EXCLUDE_FROM_ALL test_cc2pni.cc)
-add_test(test_cc2pni
+add_dumux_test(test_cc2pni test_cc2pni test_cc2pni.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/injection2pnicc-reference.vtu
@@ -19,19 +17,3 @@ add_test(test_cc2pni
   -ParameterFile ${CMAKE_CURRENT_SOURCE_DIR}/test_cc2pni.input
   -TimeManager.TEnd 1e4
   -TimeManager.DtInitial 250)
-
-set(NORMALTESTS
-  test_box2pni
-  test_cc2pni)
-set(ALLTESTS ${NORMALTESTS})
-
-# We do not want want to build the tests during make all,
-# but just build them on demand
-add_directory_test_target(_test_target)
-add_dependencies(${_test_target} ${ALLTESTS})
-set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-  PROPERTY TEST_INCLUDE_FILE ${CMAKE_CURRENT_BINARY_DIR}/BuildTests.cmake)
-
-foreach(_exe ${ALLTESTS})
-  target_link_libraries(${_exe} ${DUNE_LIBS})
-endforeach(_exe ${ALLTESTS})
diff --git a/test/implicit/3p/CMakeLists.txt b/test/implicit/3p/CMakeLists.txt
index 7ced680384..14d533405d 100644
--- a/test/implicit/3p/CMakeLists.txt
+++ b/test/implicit/3p/CMakeLists.txt
@@ -1,5 +1,4 @@
-add_executable("test_box3p" EXCLUDE_FROM_ALL test_box3p.cc)
-add_test(test_box3p
+add_dumux_test(test_box3p test_box3p test_box3p.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/infiltration3pbox-reference.vtu
@@ -8,8 +7,7 @@ add_test(test_box3p
   -ParameterFile ${CMAKE_CURRENT_SOURCE_DIR}/test_box3p.input
   -Grid.File ${CMAKE_CURRENT_SOURCE_DIR}/grids/infiltration3p.dgf)
 
-add_executable("test_cc3p" EXCLUDE_FROM_ALL test_cc3p.cc)
-add_test(test_cc3p
+add_dumux_test(test_cc3p test_cc3p test_cc3p.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/infiltration3pcc-reference.vtu
@@ -17,20 +15,3 @@ add_test(test_cc3p
   ${CMAKE_CURRENT_BINARY_DIR}/test_cc3p
   -ParameterFile ${CMAKE_CURRENT_SOURCE_DIR}/test_cc3p.input
   -Grid.File ${CMAKE_CURRENT_SOURCE_DIR}/grids/infiltration3p.dgf)
-
-
-set(NORMALTESTS
-  test_box3p
-  test_cc3p)
-set(ALLTESTS ${NORMALTESTS})
-
-# We do not want want to build the tests during make all,
-# but just build them on demand
-add_directory_test_target(_test_target)
-add_dependencies(${_test_target} ${ALLTESTS})
-set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-  PROPERTY TEST_INCLUDE_FILE ${CMAKE_CURRENT_BINARY_DIR}/BuildTests.cmake)
-
-foreach(_exe ${ALLTESTS})
-  target_link_libraries(${_exe} ${DUNE_LIBS})
-endforeach(_exe ${ALLTESTS})
diff --git a/test/implicit/3p3c/CMakeLists.txt b/test/implicit/3p3c/CMakeLists.txt
index 381ef57444..beb3135520 100644
--- a/test/implicit/3p3c/CMakeLists.txt
+++ b/test/implicit/3p3c/CMakeLists.txt
@@ -1,5 +1,4 @@
-add_executable("test_box3p3c" EXCLUDE_FROM_ALL test_box3p3c.cc)
-add_test(test_box3p3c
+add_dumux_test(test_box3p3c test_box3p3c test_box3p3c.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/infiltrationbox-reference.vtu
@@ -10,8 +9,7 @@ add_test(test_box3p3c
   -TimeManager.TEnd 8.64e5
   -TimeManager.DtInitial 8.64e4)
 
-add_executable("test_cc3p3c" EXCLUDE_FROM_ALL test_cc3p3c.cc)
-add_test(test_cc3p3c
+add_dumux_test(test_cc3p3c test_cc3p3c test_cc3p3c.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/infiltrationcc-reference.vtu
@@ -21,20 +19,3 @@ add_test(test_cc3p3c
   -Grid.File ${CMAKE_CURRENT_SOURCE_DIR}/grids/test_3p3c_coarse.dgf
   -TimeManager.TEnd 8.64e5
   -TimeManager.DtInitial 8.64e4)
-
-
-set(NORMALTESTS
-  test_box3p3c
-  test_cc3p3c)
-set(ALLTESTS ${NORMALTESTS})
-
-# We do not want want to build the tests during make all,
-# but just build them on demand
-add_directory_test_target(_test_target)
-add_dependencies(${_test_target} ${ALLTESTS})
-set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-  PROPERTY TEST_INCLUDE_FILE ${CMAKE_CURRENT_BINARY_DIR}/BuildTests.cmake)
-
-foreach(_exe ${ALLTESTS})
-  target_link_libraries(${_exe} ${DUNE_LIBS})
-endforeach(_exe ${ALLTESTS})
diff --git a/test/implicit/3p3cni/CMakeLists.txt b/test/implicit/3p3cni/CMakeLists.txt
index acba751219..36e91985c3 100644
--- a/test/implicit/3p3cni/CMakeLists.txt
+++ b/test/implicit/3p3cni/CMakeLists.txt
@@ -1,5 +1,4 @@
-add_executable("test_box3p3cni" EXCLUDE_FROM_ALL test_box3p3cni.cc)
-add_test(test_box3p3cni
+add_dumux_test(test_box3p3cni test_box3p3cni test_box3p3cni.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/column3p3cnibox-reference.vtu
@@ -8,8 +7,7 @@ add_test(test_box3p3cni
   -ParameterFile ${CMAKE_CURRENT_SOURCE_DIR}/test_box3p3cni.input
   -Grid.File ${CMAKE_CURRENT_SOURCE_DIR}/grids/column.dgf)
 
-add_executable("test_cc3p3cni" EXCLUDE_FROM_ALL test_cc3p3cni.cc)
-add_test(test_cc3p3cni
+add_dumux_test(test_cc3p3cni test_cc3p3cni test_cc3p3cni.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/column3p3cnicc-reference.vtu
@@ -17,19 +15,3 @@ add_test(test_cc3p3cni
   ${CMAKE_CURRENT_BINARY_DIR}/test_cc3p3cni
   -ParameterFile ${CMAKE_CURRENT_SOURCE_DIR}/test_cc3p3cni.input
   -Grid.File ${CMAKE_CURRENT_SOURCE_DIR}/grids/column.dgf)
-
-set(NORMALTESTS
-  test_box3p3cni
-  test_cc3p3cni)
-set(ALLTESTS ${NORMALTESTS})
-
-# We do not want want to build the tests during make all,
-# but just build them on demand
-add_directory_test_target(_test_target)
-add_dependencies(${_test_target} ${ALLTESTS})
-set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-  PROPERTY TEST_INCLUDE_FILE ${CMAKE_CURRENT_BINARY_DIR}/BuildTests.cmake)
-
-foreach(_exe ${ALLTESTS})
-  target_link_libraries(${_exe} ${DUNE_LIBS})
-endforeach(_exe ${ALLTESTS})
diff --git a/test/implicit/co2/CMakeLists.txt b/test/implicit/co2/CMakeLists.txt
index afffd2418f..0830be49bb 100644
--- a/test/implicit/co2/CMakeLists.txt
+++ b/test/implicit/co2/CMakeLists.txt
@@ -1,8 +1,5 @@
 # build target for the CO2 test problem
-add_executable("test_boxco2" EXCLUDE_FROM_ALL test_boxco2.cc)
-target_link_libraries(test_boxco2 ${DUNE_LIBS})
-add_dune_alugrid_flags(test_boxco2)
-add_test(test_boxco2
+add_dumux_test(test_boxco2 test_boxco2 test_boxco2.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/co2box-reference.vtu
@@ -10,10 +7,9 @@ add_test(test_boxco2
   ${CMAKE_CURRENT_BINARY_DIR}/test_boxco2
   -ParameterFile ${CMAKE_CURRENT_SOURCE_DIR}/test_boxco2.input
   -Grid.File ${CMAKE_CURRENT_SOURCE_DIR}/grids/heterogeneousSmall.dgf)
+add_dune_alugrid_flags(test_boxco2)
 
-add_executable("test_ccco2" EXCLUDE_FROM_ALL test_ccco2.cc)
-add_dune_alugrid_flags(test_ccco2)
-add_test(test_ccco2
+add_dumux_test(test_ccco2 test_ccco2 test_ccco2.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/co2cc-reference.vtu
@@ -21,8 +17,9 @@ add_test(test_ccco2
   ${CMAKE_CURRENT_BINARY_DIR}/test_ccco2
   -ParameterFile ${CMAKE_CURRENT_SOURCE_DIR}/test_ccco2.input
   -Grid.File ${CMAKE_CURRENT_SOURCE_DIR}/grids/heterogeneousSmall.dgf)
+add_dune_alugrid_flags(test_ccco2)
 
-add_test(test_restartco2
+add_dumux_test(test_restartco2 test_ccco2 test_ccco2.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/co2box-reference.vtu
@@ -32,15 +29,3 @@ add_test(test_restartco2
   -Grid.File ${CMAKE_CURRENT_SOURCE_DIR}/grids/heterogeneousSmall.dgf
   -Restart 42008.6
   -TimeManager.DtInitial 23452.1)
-
-set(TESTS
-  test_boxco2
-  test_ccco2
-  test_restart)
-
-# We do not want want to build the tests during make all,
-# but just build them on demand
-add_directory_test_target(_test_target)
-add_dependencies(${_test_target} ${TESTS})
-set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-  PROPERTY TEST_INCLUDE_FILE ${CMAKE_CURRENT_BINARY_DIR}/BuildTests.cmake)
diff --git a/test/implicit/co2ni/CMakeLists.txt b/test/implicit/co2ni/CMakeLists.txt
index 7b17e9a511..cf559b5680 100644
--- a/test/implicit/co2ni/CMakeLists.txt
+++ b/test/implicit/co2ni/CMakeLists.txt
@@ -1,7 +1,5 @@
 # build target for the CO2 non-isothermal test problem
-add_executable("test_boxco2ni" EXCLUDE_FROM_ALL test_boxco2ni.cc)
-add_dune_alugrid_flags(test_boxco2ni)
-add_test(test_boxco2ni
+add_dumux_test(test_boxco2ni test_boxco2ni test_boxco2ni.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/co2nibox-reference.vtu
@@ -9,10 +7,9 @@ add_test(test_boxco2ni
   ${CMAKE_CURRENT_BINARY_DIR}/test_boxco2ni
   -ParameterFile ${CMAKE_CURRENT_SOURCE_DIR}/test_boxco2ni.input
   -Grid.File ${CMAKE_CURRENT_SOURCE_DIR}/grids/heterogeneousSmall.dgf)
+add_dune_alugrid_flags(test_boxco2ni)
 
-add_executable("test_ccco2ni" EXCLUDE_FROM_ALL test_ccco2ni.cc)
-add_dune_alugrid_flags(test_ccco2ni)
-add_test(test_ccco2ni
+add_dumux_test(test_ccco2ni test_ccco2ni test_ccco2ni.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/co2nicc-reference.vtu
@@ -20,19 +17,4 @@ add_test(test_ccco2ni
   ${CMAKE_CURRENT_BINARY_DIR}/test_ccco2ni
   -ParameterFile ${CMAKE_CURRENT_SOURCE_DIR}/test_ccco2ni.input
   -Grid.File ${CMAKE_CURRENT_SOURCE_DIR}/grids/heterogeneousSmall.dgf)
-
-set(NORMALTESTS
-  test_boxco2ni
-  test_ccco2ni)
-set(ALLTESTS ${NORMALTESTS})
-
-# We do not want want to build the tests during make all,
-# but just build them on demand
-add_directory_test_target(_test_target)
-add_dependencies(${_test_target} ${ALLTESTS})
-set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-  PROPERTY TEST_INCLUDE_FILE ${CMAKE_CURRENT_BINARY_DIR}/BuildTests.cmake)
-
-foreach(_exe ${ALLTESTS})
-  target_link_libraries(${_exe} ${DUNE_LIBS})
-endforeach(_exe ${ALLTESTS})
+add_dune_alugrid_flags(test_ccco2ni)
diff --git a/test/implicit/mpnc/CMakeLists.txt b/test/implicit/mpnc/CMakeLists.txt
index 568d80d74b..056201fd15 100644
--- a/test/implicit/mpnc/CMakeLists.txt
+++ b/test/implicit/mpnc/CMakeLists.txt
@@ -1,6 +1,4 @@
-# build target for the twophase-twocomponent test problem
-add_executable("test_boxmpnc" EXCLUDE_FROM_ALL test_boxmpnc.cc)
-add_test(test_boxmpnc
+add_dumux_test(test_boxmpnc test_boxmpnc test_boxmpnc.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/obstaclebox-reference.vtu
@@ -11,8 +9,7 @@ add_test(test_boxmpnc
   -TimeManager.TEnd 1e4
   -TimeManager.DtInitial 250)
 
-add_executable("test_ccmpnc" EXCLUDE_FROM_ALL test_ccmpnc.cc)
-add_test(test_ccmpnc
+add_dumux_test(test_ccmpnc test_ccmpnc test_ccmpnc.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/obstaclecc-reference.vtu
@@ -23,9 +20,8 @@ add_test(test_ccmpnc
   -TimeManager.TEnd 1e4
   -TimeManager.DtInitial 250)
 
-# build target for the one-phase forchheimer test problem
-add_executable("test_forchheimer1p" EXCLUDE_FROM_ALL test_forchheimer1p.cc)
-add_test(test_forchheimer1p
+# build target for the one-phase Forchheimer test problem
+add_dumux_test(test_forchheimer1p test_forchheimer1p test_forchheimer1p.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/forchheimer1p-reference.vtp
@@ -34,9 +30,8 @@ add_test(test_forchheimer1p
   -ParameterFile ${CMAKE_CURRENT_SOURCE_DIR}/test_forchheimer1p.input
   -Grid.File ${CMAKE_CURRENT_SOURCE_DIR}/grids/forchheimer1d.dgf)
 
-# build target for the two-phase forchheimer test problem
-add_executable("test_forchheimer2p" EXCLUDE_FROM_ALL test_forchheimer2p.cc)
-add_test(test_forchheimer2p
+# build target for the two-phase Forchheimer test problem
+add_dumux_test(test_forchheimer2p test_forchheimer2p test_forchheimer2p.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/forchheimer2p-reference.vtu
@@ -45,8 +40,7 @@ add_test(test_forchheimer2p
   -ParameterFile ${CMAKE_CURRENT_SOURCE_DIR}/test_forchheimer2p.input
   -Grid.File ${CMAKE_CURRENT_SOURCE_DIR}/grids/obstacle_24x16.dgf)
 
-add_executable("test_boxmpnckinetic" EXCLUDE_FROM_ALL test_boxmpnckinetic.cc)
-add_test(test_boxmpnckinetic
+add_dumux_test(test_boxmpnckinetic test_boxmpnckinetic test_boxmpnckinetic.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/evaporationatmosphere-reference.vtu
@@ -58,22 +52,3 @@ add_test(test_boxmpnckinetic
   -TimeManager.DtInitial 1e-2)
 add_dune_alugrid_flags(test_boxmpnckinetic)
 add_dune_ug_flags(test_boxmpnckinetic)
-
-set(NORMALTESTS
-  test_boxmpnc
-  test_ccmpnc
-  test_forchheimer1p
-  test_forchheimer2p
-  test_boxmpnckinetic)
-set(ALLTESTS ${NORMALTESTS})
-
-# We do not want want to build the tests during make all,
-# but just build them on demand
-add_directory_test_target(_test_target)
-add_dependencies(${_test_target} ${ALLTESTS})
-set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-  PROPERTY TEST_INCLUDE_FILE ${CMAKE_CURRENT_BINARY_DIR}/BuildTests.cmake)
-
-foreach(_exe ${ALLTESTS})
-  target_link_libraries(${_exe} ${DUNE_LIBS} ${MPI_LIBRARIES})
-endforeach(_exe ${ALLTESTS})
diff --git a/test/implicit/richards/CMakeLists.txt b/test/implicit/richards/CMakeLists.txt
index 57251d7176..0a0ef934c1 100644
--- a/test/implicit/richards/CMakeLists.txt
+++ b/test/implicit/richards/CMakeLists.txt
@@ -1,8 +1,6 @@
 # build target for the Richards test problem
-add_executable("test_boxrichards" EXCLUDE_FROM_ALL test_boxrichards.cc)
 if(MPI_CXX_FOUND)
-  add_dune_mpi_flags(test_boxrichards)
-  add_test(test_boxrichards
+  add_dumux_test(test_boxrichards test_boxrichards test_boxrichards.cc
     ${CMAKE_SOURCE_DIR}/bin/runTest.sh
     ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
     ${CMAKE_SOURCE_DIR}/test/references/richardslensbox-reference-parallel.vtu
@@ -12,8 +10,9 @@ if(MPI_CXX_FOUND)
     -Grid.File ${CMAKE_CURRENT_SOURCE_DIR}/grids/richardslens-24x16.dgf
     -TimeManager.TEnd 3000
     -TimeManager.DtInitial 100)
+  add_dune_mpi_flags(test_boxrichards)
 else()
-  add_test(test_boxrichards
+  add_dumux_test(test_boxrichards test_boxrichards test_boxrichards.cc
     ${CMAKE_SOURCE_DIR}/bin/runTest.sh
     ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
     ${CMAKE_SOURCE_DIR}/test/references/richardslensbox-reference.vtu
@@ -25,8 +24,7 @@ else()
     -TimeManager.DtInitial 100)
 endif(MPI_CXX_FOUND)
 
-add_executable("test_ccrichards" EXCLUDE_FROM_ALL test_ccrichards.cc)
-add_test(test_ccrichards
+add_dumux_test(test_ccrichards test_ccrichards test_ccrichards.cc
   ${CMAKE_SOURCE_DIR}/bin/runTest.sh
   ${CMAKE_SOURCE_DIR}/bin/fuzzycomparevtu.py
   ${CMAKE_SOURCE_DIR}/test/references/richardslenscc-reference.vtu
@@ -36,19 +34,3 @@ add_test(test_ccrichards
   -Grid.File ${CMAKE_CURRENT_SOURCE_DIR}/grids/richardslens-24x16.dgf
   -TimeManager.TEnd 3000
   -TimeManager.DtInitial 100)
-
-set(NORMALTESTS
-  test_boxrichards
-  test_ccrichards)
-set(ALLTESTS ${NORMALTESTS})
-
-# We do not want want to build the tests during make all,
-# but just build them on demand
-add_directory_test_target(_test_target)
-add_dependencies(${_test_target} ${ALLTESTS})
-set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-  PROPERTY TEST_INCLUDE_FILE ${CMAKE_CURRENT_BINARY_DIR}/BuildTests.cmake)
-
-foreach(_exe ${ALLTESTS})
-  target_link_libraries(${_exe} ${DUNE_LIBS})
-endforeach(_exe ${ALLTESTS})
diff --git a/test/material/fluidsystems/CMakeLists.txt b/test/material/fluidsystems/CMakeLists.txt
index ebfafc2542..c3cca99ed4 100644
--- a/test/material/fluidsystems/CMakeLists.txt
+++ b/test/material/fluidsystems/CMakeLists.txt
@@ -1,17 +1,2 @@
-add_executable("test_fluidsystems" EXCLUDE_FROM_ALL test_fluidsystems.cc)
-add_test(test_fluidsystems
+add_dumux_test(test_fluidsystems test_fluidsystems test_fluidsystems.cc
   ${CMAKE_CURRENT_BINARY_DIR}/test_fluidsystems)
-
-set(NORMALTESTS test_fluidsystems)
-set(ALLTESTS ${NORMALTESTS})
-
-# We do not want want to build the tests during make all,
-# but just build them on demand
-add_directory_test_target(_test_target)
-add_dependencies(${_test_target} ${ALLTESTS})
-set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-  PROPERTY TEST_INCLUDE_FILE ${CMAKE_CURRENT_BINARY_DIR}/BuildTests.cmake)
-
-foreach(_exe ${ALLTESTS})
-  target_link_libraries(${_exe} ${DUNE_LIBS})
-endforeach(_exe ${ALLTESTS})
diff --git a/test/material/immiscibleflash/CMakeLists.txt b/test/material/immiscibleflash/CMakeLists.txt
index f768b9047f..ff678e219d 100644
--- a/test/material/immiscibleflash/CMakeLists.txt
+++ b/test/material/immiscibleflash/CMakeLists.txt
@@ -1,17 +1,2 @@
-add_executable("test_immiscibleflash" EXCLUDE_FROM_ALL test_immiscibleflash.cc)
-add_test(test_immiscibleflash
+add_dumux_test(test_immiscibleflash test_immiscibleflash test_immiscibleflash.cc
   ${CMAKE_CURRENT_BINARY_DIR}/test_immiscibleflash)
-
-set(NORMALTESTS test_immiscibleflash)
-set(ALLTESTS ${NORMALTESTS})
-
-# We do not want want to build the tests during make all,
-# but just build them on demand
-add_directory_test_target(_test_target)
-add_dependencies(${_test_target} ${ALLTESTS})
-set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-  PROPERTY TEST_INCLUDE_FILE ${CMAKE_CURRENT_BINARY_DIR}/BuildTests.cmake)
-
-foreach(_exe ${ALLTESTS})
-  target_link_libraries(${_exe} ${DUNE_LIBS})
-endforeach(_exe ${ALLTESTS})
diff --git a/test/material/ncpflash/CMakeLists.txt b/test/material/ncpflash/CMakeLists.txt
index 25db0c25e7..5b1d19175f 100644
--- a/test/material/ncpflash/CMakeLists.txt
+++ b/test/material/ncpflash/CMakeLists.txt
@@ -1,17 +1,2 @@
-add_executable("test_ncpflash" EXCLUDE_FROM_ALL test_ncpflash.cc)
-add_test(test_ncpflash
+add_dumux_test(test_ncpflash test_ncpflash test_ncpflash.cc
   ${CMAKE_CURRENT_BINARY_DIR}/test_ncpflash)
-
-set(NORMALTESTS test_ncpflash)
-set(ALLTESTS ${NORMALTESTS})
-
-# We do not want want to build the tests during make all,
-# but just build them on demand
-add_directory_test_target(_test_target)
-add_dependencies(${_test_target} ${ALLTESTS})
-set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-  PROPERTY TEST_INCLUDE_FILE ${CMAKE_CURRENT_BINARY_DIR}/BuildTests.cmake)
-
-foreach(_exe ${ALLTESTS})
-  target_link_libraries(${_exe} ${DUNE_LIBS})
-endforeach(_exe ${ALLTESTS})
diff --git a/test/material/pengrobinson/CMakeLists.txt b/test/material/pengrobinson/CMakeLists.txt
index ea2a5d2b1f..a9d6b95332 100644
--- a/test/material/pengrobinson/CMakeLists.txt
+++ b/test/material/pengrobinson/CMakeLists.txt
@@ -1,17 +1,2 @@
-add_executable("test_pengrobinson" EXCLUDE_FROM_ALL test_pengrobinson.cc)
-add_test(test_pengrobinson
+add_dumux_test(test_pengrobinson test_pengrobinson test_pengrobinson.cc
   ${CMAKE_CURRENT_BINARY_DIR}/test_pengrobinson)
-
-set(NORMALTESTS test_pengrobinson)
-set(ALLTESTS ${NORMALTESTS})
-
-# We do not want want to build the tests during make all,
-# but just build them on demand
-add_directory_test_target(_test_target)
-add_dependencies(${_test_target} ${ALLTESTS})
-set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-  PROPERTY TEST_INCLUDE_FILE ${CMAKE_CURRENT_BINARY_DIR}/BuildTests.cmake)
-
-foreach(_exe ${ALLTESTS})
-  target_link_libraries(${_exe} ${DUNE_LIBS})
-endforeach(_exe ${ALLTESTS})
diff --git a/test/material/tabulation/CMakeLists.txt b/test/material/tabulation/CMakeLists.txt
index a8687198d0..8322fe3ec9 100644
--- a/test/material/tabulation/CMakeLists.txt
+++ b/test/material/tabulation/CMakeLists.txt
@@ -1,17 +1,2 @@
-add_executable("test_tabulation" EXCLUDE_FROM_ALL test_tabulation.cc)
-add_test(test_tabulation
+add_dumux_test(test_tabulation test_tabulation test_tabulation.cc
   ${CMAKE_CURRENT_BINARY_DIR}/test_tabulation)
-
-set(NORMALTESTS test_tabulation)
-set(ALLTESTS ${NORMALTESTS})
-
-# We do not want want to build the tests during make all,
-# but just build them on demand
-add_directory_test_target(_test_target)
-add_dependencies(${_test_target} ${ALLTESTS})
-set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-  PROPERTY TEST_INCLUDE_FILE ${CMAKE_CURRENT_BINARY_DIR}/BuildTests.cmake)
-
-foreach(_exe ${ALLTESTS})
-  target_link_libraries(${_exe} ${DUNE_LIBS})
-endforeach(_exe ${ALLTESTS})
-- 
GitLab