private boolean executeTestMethod()

in surefire-providers/surefire-junit3/src/main/java/org/apache/maven/surefire/junit/PojoTestSetExecutor.java [70:143]


    private boolean executeTestMethod(Class<?> testClass, Method method, long testRunId, DiscoveredTestMethods methods)
            throws TestSetFailedException {
        final Object testObject;

        try {
            testObject = testClass.getDeclaredConstructor().newInstance();
        } catch (ReflectiveOperationException e) {
            throw new TestSetFailedException("Unable to instantiate POJO '" + testClass + "'.", e);
        }

        final String testClassName = testClass.getName();
        final String methodName = method.getName();
        final String userFriendlyMethodName = methodName + "()";
        final String testName = getTestName(testClassName, userFriendlyMethodName);

        reporter.testStarting(new SimpleReportEntry(NORMAL_RUN, testRunId, testClassName, null, testName, null));

        try {
            setUpFixture(testObject, methods);
        } catch (Throwable e) {
            StackTraceWriter stackTraceWriter = new LegacyPojoStackTraceWriter(testClassName, methodName, e);
            reporter.testFailed(
                    withException(NORMAL_RUN, testRunId, testClassName, null, testName, null, stackTraceWriter));

            // A return value of true indicates to this class's executeTestMethods
            // method that it should abort and not attempt to execute
            // any other test methods. The other caller of this method,
            // TestRerunner.rerun, ignores this return value, because it is
            // only running one test.
            return true;
        }

        // Make sure that tearDownFixture
        try {
            method.invoke(testObject, EMPTY_OBJECT_ARRAY);
            reporter.testSucceeded(new SimpleReportEntry(NORMAL_RUN, testRunId, testClassName, null, testName, null));
        } catch (InvocationTargetException e) {
            Throwable t = e.getTargetException();
            StackTraceWriter stackTraceWriter = new LegacyPojoStackTraceWriter(testClassName, methodName, t);
            reporter.testFailed(
                    withException(NORMAL_RUN, testRunId, testClassName, null, testName, null, stackTraceWriter));
            // Don't return  here, because tearDownFixture should be called even
            // if the test method throws an exception.
        } catch (Throwable t) {
            StackTraceWriter stackTraceWriter = new LegacyPojoStackTraceWriter(testClassName, methodName, t);
            reporter.testFailed(
                    withException(NORMAL_RUN, testRunId, testClassName, null, testName, null, stackTraceWriter));
            // Don't return  here, because tearDownFixture should be called even
            // if the test method throws an exception.
        }

        try {
            tearDownFixture(testObject, methods);
        } catch (Throwable t) {
            StackTraceWriter stackTraceWriter = new LegacyPojoStackTraceWriter(testClassName, methodName, t);
            // Treat any exception from tearDownFixture as a failure of the test.
            reporter.testFailed(
                    withException(NORMAL_RUN, testRunId, testClassName, null, testName, null, stackTraceWriter));

            // A return value of true indicates to this class's executeTestMethods
            // method that it should abort and not attempt to execute
            // any other test methods. The other caller of this method,
            // TestRerunner.rerun, ignores this return value, because it is
            // only running one test.
            return true;
        }

        // A return value of false indicates to this class's executeTestMethods
        // method that it should keep plowing ahead and invoke more test methods.
        // The other caller of this method,
        // TestRerunner.rerun, ignores this return value, because it is
        // only running one test.
        return false;
    }