diff --git a/cmake/scripts/FindFiles.cmake b/cmake/scripts/FindFiles.cmake
index e4832811d0274e54065b4aaf53ad177437d9594e..fa012d8c5ac0730ac80301c3a3a9cf9d6f753824 100644
--- a/cmake/scripts/FindFiles.cmake
+++ b/cmake/scripts/FindFiles.cmake
@@ -2,10 +2,13 @@
 cmake_policy(SET CMP0009 NEW)
 file(GLOB_RECURSE makefiles RELATIVE ${RELPATH} "CMakeLists.txt")
 foreach(_file ${makefiles})
-  string(REGEX MATCH ".*/test$" _testdir ${_file})
-  if(_testdir)
+  # path contains "/test"
+  string(REGEX MATCH ".*/test" _testdir ${_file})
+  # path end with "/test" and not "/testFoo" or "/test/foo"
+  string(REGEX MATCH ".*/test/CMakeLists.txt$" _testdirensured ${_file})
+  if(_testdir AND _testdirensured)
     list(APPEND _makefiles ${_testdir})
-  endif(_testdir)
+  endif(_testdir AND _testdirensured)
 endforeach(_file ${makefiles})
 if(_makefiles)
   message("${_makefiles}")