diff --git a/Makefile.am b/Makefile.am
index 18b7c0e3db895ed58f2657756273e8c89d538fd2..1d2c1c740a86ac9b408818d0f2987abe3c42e459 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -65,6 +65,8 @@ test_cases = \
 	tests/extensions/vacation/execute.svtest \
 	$(ENOTIFY_TESTS)
 
+if HAVE_DOVECOT_LIBS
+
 $(test_cases):
 	@$(TESTSUITE_BIN) $@
 
@@ -72,3 +74,9 @@ $(test_cases):
 
 test: $(test_cases)
 
+else
+
+test:
+	@echo "Cannot compile or execute the testsuite without the Dovecot sources."
+
+endif