Search in sources :

Example 1 with IResult

use of org.springsource.loaded.test.infra.IResult in project spring-loaded by spring-projects.

the class ExploreAllChoicesRunner method getChildren.

@Override
protected List<GeneratedTest> getChildren() {
    if (!generatedTestsOn)
        return Collections.emptyList();
    if (children != null)
        return children;
    List<GeneratedTest> newChildren = new ArrayList<GeneratedTest>();
    try {
        SystematicChoiceGenerator choiceGenerator = new SystematicChoiceGenerator();
        do {
            GenerativeTest test = testClass.newInstance();
            //Inject a choice generator into the test!
            test.choiceGenerator = choiceGenerator;
            test.generative = true;
            try {
                test.setup();
                IResult r = null;
                if (predictResults) {
                    try {
                        //run test in generative mode
                        r = test.test();
                    } catch (ResultException e) {
                        r = e;
                    } catch (RejectedChoice e) {
                        //Choices shouldn't be rejected during test run only during setup!
                        throw new IllegalStateException(e);
                    }
                }
                addTest(newChildren, new GeneratedTest(choiceGenerator.choices, r, test.getConfigDescription()));
            } catch (RejectedChoice e) {
            //Ignore this test
            } finally {
                test.teardown();
            }
        } while (choiceGenerator.backtrack());
        children = newChildren;
        return newChildren;
    } catch (Exception e) {
        //  children and should never raise any errors.
        throw new Error(e);
    }
}
Also used : ArrayList(java.util.ArrayList) InitializationError(org.junit.runners.model.InitializationError) ResultException(org.springsource.loaded.test.infra.ResultException) ResultException(org.springsource.loaded.test.infra.ResultException) IResult(org.springsource.loaded.test.infra.IResult)

Example 2 with IResult

use of org.springsource.loaded.test.infra.IResult in project spring-loaded by spring-projects.

the class ExploreAllChoicesRunner method runChild.

@Override
protected void runChild(GeneratedTest testPredicted, RunNotifier notifier) {
    notifier.fireTestStarted(describeChild(testPredicted));
    try {
        //Determine expected test result first:
        IResult expectedResult = testPredicted.getExpectedResult();
        if (expectedResult == null) {
            //Suite was not created with @PredictResult must predict it now
            GenerativeTest test = testClass.newInstance();
            //Inject a choice generator into the test!
            test.choiceGenerator = new SystematicChoiceGenerator(testPredicted.getChoices());
            test.generative = true;
            try {
                test.setup();
                expectedResult = test.test();
            } catch (ResultException e) {
                expectedResult = e;
            } finally {
                test.teardown();
            }
        }
        //Run the test again and verify
        GenerativeTest test = testClass.newInstance();
        //Inject a choice generator into the test!
        test.choiceGenerator = new SystematicChoiceGenerator(testPredicted.getChoices());
        test.generative = false;
        try {
            test.setup();
            Assert.assertEquals(testPredicted.getConfigDescription(), test.getConfigDescription());
            IResult actual;
            try {
                //run test in verify mode
                actual = test.test();
            } catch (ResultException e) {
                actual = e;
            }
            test.assertEqualIResults(expectedResult, actual);
        } finally {
            test.teardown();
        }
    } catch (Throwable e) {
        notifier.fireTestFailure(new Failure(describeChild(testPredicted), e));
    } finally {
        notifier.fireTestFinished(describeChild(testPredicted));
    }
}
Also used : ResultException(org.springsource.loaded.test.infra.ResultException) Failure(org.junit.runner.notification.Failure) IResult(org.springsource.loaded.test.infra.IResult)

Aggregations

IResult (org.springsource.loaded.test.infra.IResult)2 ResultException (org.springsource.loaded.test.infra.ResultException)2 ArrayList (java.util.ArrayList)1 Failure (org.junit.runner.notification.Failure)1 InitializationError (org.junit.runners.model.InitializationError)1