diff --git a/tests/namedb.c b/tests/namedb.c
index e452f98254c29db1da6d44e0e6a1e3bdf59316f4..3074d4621c82d74447387163756ee1daad9ff153 100644
--- a/tests/namedb.c
+++ b/tests/namedb.c
@@ -14,6 +14,7 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <dirent.h>
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
@@ -172,7 +173,22 @@ int main(int argc, char *argv[])
 	namedb_test_set(nkeys, keys, dbid, namedb_lmdb_api(), &pool);
 	namedb_test_set(nkeys, keys, NULL, namedb_trie_api(), &pool);
 
-	/* Cleanup */
+	/* Cleanup. */
 	mp_delete(pool.ctx);
+
+	/* Cleanup temporary DB. */
+	DIR *dir = opendir(dbid);
+	struct dirent *dp;
+	while ((dp = readdir(dir)) != NULL) {
+		if (dp->d_name[0] == '.') {
+			continue;
+		}
+		char *file = sprintf_alloc("%s/%s", dbid, dp->d_name);
+		remove(file);
+		free(file);
+	}
+	closedir(dir);
+	remove(dbid);
+
 	return 0;
 }
diff --git a/tests/zone_timers.c b/tests/zone_timers.c
index dd12998c55a23d02951fb430470d164b8f6ddde8..01fe3f1efcdb116ba5b8b6193793b1a48d83c31a 100644
--- a/tests/zone_timers.c
+++ b/tests/zone_timers.c
@@ -14,11 +14,13 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <dirent.h>
 #include <stdlib.h>
 #include <time.h>
 #include <tap/basic.h>
 
 #include "libknot/common.h"
+#include "common/mem.h"
 #include "common/namedb/namedb.h"
 #include "common/namedb/namedb_lmdb.h"
 #include "knot/zone/timers.h"
@@ -119,6 +121,23 @@ int main(int argc, char *argv[])
 	zone_free(&zone_2);
 	close_timers_db(db);
 
+	// Cleanup temporary DB.
+	char *timers_dir = sprintf_alloc("%s/timers", dbid);
+	DIR *dir = opendir(timers_dir);
+	struct dirent *dp;
+	while ((dp = readdir(dir)) != NULL) {
+		if (dp->d_name[0] == '.') {
+			continue;
+		}
+		char *file = sprintf_alloc("%s/%s", timers_dir, dp->d_name);
+		remove(file);
+		free(file);
+	}
+	closedir(dir);
+	remove(timers_dir);
+	free(timers_dir);
+	remove(dbid);
+
 	return EXIT_SUCCESS;
 }