diff --git a/scripts/test_db_connectivity.js b/scripts/test_db_connectivity.js
new file mode 100755
index 0000000000000000000000000000000000000000..2a446931742ee6b531700c78839d835acaee104c
--- /dev/null
+++ b/scripts/test_db_connectivity.js
@@ -0,0 +1,16 @@
+#!/usr/bin/env node
+
+// a simple script to test to see if we can connect to
+// the database using the present configuration.
+
+const
+configuration = require('../libs/configuration.js'),
+db = require('../browserid/lib/db.js');
+
+var dbCfg = configuration.get('database');
+
+db.open(dbCfg, function (r) {
+  function end() { process.exit(r === undefined ? 0 : 1); }
+  if (r === undefined) db.close(end);
+  else end();
+});
diff --git a/test.sh b/test.sh
index 7c77d81e7e49ed83519ef3e51a052826b310a5bf..7dec3f2b6fedfd6b8b16035156f1f5ff732ac050 100755
--- a/test.sh
+++ b/test.sh
@@ -8,11 +8,16 @@ fi
 
 for env in test_json test_mysql ; do
   export NODE_ENV=$env
-  echo "Testing with NODE_ENV=$env"
-  for file in browserid/tests/*.js ; do
-      vows $file
-      if [[ $? != 0 ]] ; then
-          exit 1
-      fi
-  done
+  ./scripts/test_db_connectivity.js
+  if [ $? = 0 ] ; then 
+      echo "Testing with NODE_ENV=$env"
+      for file in browserid/tests/*.js ; do
+          vows $file
+          if [[ $? != 0 ]] ; then
+              exit 1
+          fi
+      done
+  else
+      echo "CANNOT TEST '$env' ENVIRONMENT: can't connect to the database"
+  fi
 done