Search in sources :

Example 1 with Results

use of org.whole.lang.tests.model.Results in project whole by wholeplatform.

the class TestsInterpreterVisitor method visit.

@Override
public void visit(TestCase entity) {
    String name = entity.getName().getValue();
    Results results = TestsEntityFactory.instance.createResults();
    printWriter().printf("* %s test case running:\n\n", name);
    try {
        IEntityIterator<BeforeTestCase> beforeIterator = IteratorFactory.<BeforeTestCase>childMatcherIterator().withPattern(BeforeTestCase);
        beforeIterator.reset(entity.getAspects());
        for (BeforeTestCase beforeTestCase : beforeIterator) {
            beforeTestCase.accept(this);
            getResult();
        }
        Tests tests = entity.getTests();
        for (int i = 0; i < tests.wSize(); i++) {
            Test test = tests.get(i);
            if (getBindings().wIsSet("runSingleTest") && getBindings().wGet("runSingleTest") != test)
                continue;
            test.accept(this);
            IntLiteral result = null;
            switch(getResult().wGet(outcome).wEnumValue().getOrdinal()) {
                case OutcomeEnum.ERROR_ord:
                    result = results.getErrors();
                    break;
                case OutcomeEnum.FAILURE_ord:
                    result = results.getFailures();
                    break;
                case OutcomeEnum.SUCCESS_ord:
                    result = results.getSuccesses();
                    break;
                default:
                    throw new WholeIllegalArgumentException("unsupported outcome");
            }
            result.setValue(result.getValue() + 1);
        }
        IEntityIterator<AfterTestCase> afterIterator = IteratorFactory.<AfterTestCase>childMatcherIterator().withPattern(AfterTestCase);
        afterIterator.reset(entity.getAspects());
        for (AfterTestCase afterTestCase : afterIterator) {
            afterTestCase.accept(this);
            getResult();
        }
        boolean testCaseSuccess = results.getErrors().getValue() + results.getFailures().getValue() == 0;
        printWriter().printf("\n* %s test case %s\n", name, testCaseSuccess ? "OK" : "FAILED");
    } catch (OperationCanceledException e) {
        throw e;
    } catch (RuntimeException e) {
        reportError(name, e);
        results.getErrors().setValue(entity.getTests().wSize());
        results.getFailures().setValue(0);
        results.getSuccesses().setValue(0);
    }
    if (EntityUtils.isResolver(entity.getExpectedResults()))
        entity.setExpectedResults(EntityUtils.clone(results));
    if (!Matcher.match(results, entity.getActualResults()))
        entity.setActualResults(results);
    setResult(results);
}
Also used : AfterTestCase(org.whole.lang.tests.model.AfterTestCase) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException) Tests(org.whole.lang.tests.model.Tests) Constraint(org.whole.lang.tests.model.Constraint) IWholeRuntimeException(org.whole.lang.exceptions.IWholeRuntimeException) Results(org.whole.lang.tests.model.Results) Test(org.whole.lang.tests.model.Test) BeforeTest(org.whole.lang.tests.model.BeforeTest) AfterTest(org.whole.lang.tests.model.AfterTest) IntLiteral(org.whole.lang.tests.model.IntLiteral) BeforeTestCase(org.whole.lang.tests.model.BeforeTestCase)

Example 2 with Results

use of org.whole.lang.tests.model.Results in project whole by wholeplatform.

the class TestsInterpreterVisitor method visit.

@Override
public void visit(TestSuite entity) {
    Results results = TestsEntityFactory.instance.createResults();
    printWriter().printf("=== %s test suite ===\n\n", entity.getName().getValue());
    getBindings().wDefValue("filterRulesMap", TestsHelpers.createFilterRulesMap(entity));
    TestCases testCases = entity.getTestCases();
    for (int i = 0; i < testCases.wSize(); i++) {
        TestCase testCase = testCases.get(i);
        if (getBindings().wIsSet("runSingleTest") && getBindings().wGet("runSingleTest").wGetParent().wGetParent() != testCase)
            continue;
        testCase.accept(this);
        Results testCaseResults = (Results) getResult();
        results.getErrors().setValue(results.getErrors().getValue() + testCaseResults.getErrors().getValue());
        results.getFailures().setValue(results.getFailures().getValue() + testCaseResults.getFailures().getValue());
        results.getSuccesses().setValue(results.getSuccesses().getValue() + testCaseResults.getSuccesses().getValue());
    }
    if (EntityUtils.isResolver(entity.getExpectedResults()))
        entity.setExpectedResults(EntityUtils.clone(results));
    if (!Matcher.match(results, entity.getActualResults()))
        entity.setActualResults(results);
    setResult(results);
}
Also used : Results(org.whole.lang.tests.model.Results) TestCase(org.whole.lang.tests.model.TestCase) AfterTestCase(org.whole.lang.tests.model.AfterTestCase) BeforeTestCase(org.whole.lang.tests.model.BeforeTestCase) TestCases(org.whole.lang.tests.model.TestCases) Constraint(org.whole.lang.tests.model.Constraint)

Aggregations

AfterTestCase (org.whole.lang.tests.model.AfterTestCase)2 BeforeTestCase (org.whole.lang.tests.model.BeforeTestCase)2 Constraint (org.whole.lang.tests.model.Constraint)2 Results (org.whole.lang.tests.model.Results)2 IWholeRuntimeException (org.whole.lang.exceptions.IWholeRuntimeException)1 WholeIllegalArgumentException (org.whole.lang.exceptions.WholeIllegalArgumentException)1 OperationCanceledException (org.whole.lang.operations.OperationCanceledException)1 AfterTest (org.whole.lang.tests.model.AfterTest)1 BeforeTest (org.whole.lang.tests.model.BeforeTest)1 IntLiteral (org.whole.lang.tests.model.IntLiteral)1 Test (org.whole.lang.tests.model.Test)1 TestCase (org.whole.lang.tests.model.TestCase)1 TestCases (org.whole.lang.tests.model.TestCases)1 Tests (org.whole.lang.tests.model.Tests)1