private void doRun() {
            TestCase currentCase;
            while (true) {
                synchronized (lock) {
                    if (currentCaseIndex == cases.size()) {
                        break;
                    }
                    currentCase = cases.get(currentCaseIndex);
                }

                try {
                    runTestCase(currentCase);
                } catch (NoTestsRemainException ex) {
                    // Don't care about empty test classes.
                } catch (InitializationError ex) {
                    synchronized (lock) {
                        if (Thread.currentThread().isInterrupted()) {
                            break;
                        }
                        currentCase.status = TestCase.Status.FAILED;
                        currentCase.message = "Failed to initialize test: " + ex.getMessage();
                        if (!ex.getCauses().isEmpty()) {
                            currentCase.message += "\n" + ex.getCauses().get(0).getMessage();
                            currentCase.exception = new CaughtException(ex.getCauses().get(0));
                        }
                    }
                } catch (Exception ex) {
                    synchronized (lock) {
                        if (Thread.currentThread().isInterrupted()) {
                            break;
                        }
                        currentCase.status = TestCase.Status.FAILED;
                        currentCase.message = "Failed to run test.";
                        currentCase.exception = new CaughtException(ex);
                    }
                }

                synchronized (lock) {
                    if (Thread.currentThread().isInterrupted()) {
                        break;
                    }
                    currentCaseIndex += 1;
                }
            }
        }