diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php
index aed66fa..ca5ec1e 100644
--- a/modules/simpletest/drupal_web_test_case.php
+++ b/modules/simpletest/drupal_web_test_case.php
@@ -90,6 +90,15 @@ abstract class DrupalTestCase {
   protected $setupEnvironment = FALSE;
 
   /**
+   * Whether to die in case any test assertion fails.
+   *
+   * @see run-tests.sh
+    *
+    * @var boolean
+  */
+  public $dieOnFail = FALSE;
+
+  /**
    * Constructor for DrupalTestCase.
    *
    * @param $test_id
@@ -103,7 +112,7 @@ abstract class DrupalTestCase {
    * Internal helper: stores the assert.
    *
    * @param $status
-   *   Can be 'pass', 'fail', 'exception'.
+   *   Can be 'pass', 'fail', 'exception', 'debug'.
    *   TRUE is a synonym for 'pass', FALSE for 'fail'.
    * @param $message
    *   The message string.
@@ -154,6 +163,9 @@ abstract class DrupalTestCase {
       return TRUE;
     }
     else {
+       if ($this->dieOnFail && ($status == 'fail' || $status == 'exception')) {
+         exit(1);
+       }
       return FALSE;
     }
   }
diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh
index 9078168..5d5c101 100755
--- a/scripts/run-tests.sh
+++ b/scripts/run-tests.sh
@@ -78,7 +78,9 @@ simpletest_script_reporter_init();
 $test_id = db_insert('simpletest_test_id')->useDefaults(array('test_id'))->execute();
 
 // Execute tests.
-simpletest_script_execute_batch($test_id, simpletest_script_get_test_list());
+for ($i = 0; $i < $args['repeat']; $i++) {
+  simpletest_script_execute_batch($test_id, $test_list);
+}
 
 // Retrieve the last database prefix used for testing and the last test class
 // that was run from. Use the information to read the lgo file in case any
@@ -150,6 +152,15 @@ All arguments are long options.
 
   --verbose   Output detailed assertion messages in addition to summary.
 
+  --repeat    Number of times to repeat the test.
+
+  --die-on-fail
+
+              Exit test execution immediately upon any failed assertion. This
+              allows to access the test site by changing settings.php to use the
+              test database and configuration directories. Use in combination
+              with --repeat for debugging random test failures.
+
   <test1>[,<test2>[,<test3> ...]]
 
               One or more tests to be run. By default, these are interpreted
@@ -193,6 +204,8 @@ function simpletest_script_parse_args() {
     'color' => FALSE,
     'verbose' => FALSE,
     'test_names' => array(),
+    'repeat' => 1,
+    'die-on-fail' => FALSE,
     // Used internally.
     'test-id' => 0,
     'execute-test' => '',
@@ -347,6 +360,13 @@ function simpletest_script_execute_batch($test_id, $test_classes) {
         proc_close($child['process']);
         if ($status['exitcode']) {
           echo 'FATAL ' . $test_class . ': test runner returned a non-zero error code (' . $status['exitcode'] . ').' . "\n";
+          if ($args['die-on-fail']) {
+            list($db_prefix, ) = simpletest_last_test_get($test_id);
+            $public_files = variable_get('file_public_path', conf_path() . '/files');
+            $test_directory = $public_files . '/simpletest/' . substr($db_prefix, 10);
+            echo 'Simpletest database and files kept and test exited immediately on fail so should be reproducible if you change settings.php to use the database prefix '. $db_prefix . ' and config directories in '. $test_directory . "\n";
+            exit();
+          }
         }
         unset($children[$cid]);
       }
@@ -358,6 +378,8 @@ function simpletest_script_execute_batch($test_id, $test_classes) {
  * Bootstrap Drupal and run a single test.
  */
 function simpletest_script_run_one_test($test_id, $test_class) {
+  global $args;
+
   try {
     // Bootstrap Drupal.
     drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
@@ -365,6 +387,7 @@ function simpletest_script_run_one_test($test_id, $test_class) {
     simpletest_classloader_register();
 
     $test = new $test_class($test_id);
+    $test->dieOnFail = (bool) $args['die-on-fail'];
     $test->run();
     $info = $test->getInfo();
 
@@ -394,8 +417,10 @@ function simpletest_script_command($test_id, $test_class) {
   global $args, $php;
 
   $command = escapeshellarg($php) . ' ' . escapeshellarg('./scripts/' . $args['script']) . ' --url ' . escapeshellarg($args['url']);
-  if ($args['color']) {
-    $command .= ' --color';
+  foreach (array('color', 'die-on-fail') as $arg) {
+    if ($args[$arg]) {
+      $command .= ' --' . $arg;
+    }
   }
   $command .= " --php " . escapeshellarg($php) . " --test-id $test_id --execute-test " . escapeshellarg($test_class);
   return $command;
