Search in sources :

Example 1 with GridAbstractTest

use of org.apache.ignite.testframework.junits.GridAbstractTest in project ignite by apache.

the class IgniteTestSuite method addTestMethod.

/**
     * Add test method.
     *
     * @param m Test method.
     * @param names Test name list.
     * @param theClass Test class.
     * @param clsIgnore Class ignore descriptor (if any).
     * @return Result.
     */
private AddResult addTestMethod(Method m, List<String> names, Class<?> theClass, @Nullable IgnoreDescriptor clsIgnore) {
    String name = m.getName();
    if (names.contains(name))
        return new AddResult(false, null);
    if (!isPublicTestMethod(m)) {
        if (isTestMethod(m))
            addTest(warning("Test method isn't public: " + m.getName() + "(" + theClass.getCanonicalName() + ")"));
        return new AddResult(false, null);
    }
    names.add(name);
    IgnoreDescriptor ignore = IgnoreDescriptor.forMethod(theClass, m);
    if (ignore == null)
        ignore = clsIgnore;
    if (ignoredOnly) {
        if (ignore != null) {
            Test test = createTest(theClass, name);
            if (ignore.forceFailure()) {
                if (test instanceof GridAbstractTest)
                    ((GridAbstractTest) test).forceFailure(ignore.reason());
                else
                    test = new ForcedFailure(name, ignore.reason());
            }
            addTest(test);
            return new AddResult(true, test);
        }
    } else {
        if (ignore == null) {
            Test test = createTest(theClass, name);
            addTest(test);
            return new AddResult(true, test);
        }
    }
    return new AddResult(false, null);
}
Also used : GridAbstractTest(org.apache.ignite.testframework.junits.GridAbstractTest) Test(junit.framework.Test) GridAbstractTest(org.apache.ignite.testframework.junits.GridAbstractTest)

Example 2 with GridAbstractTest

use of org.apache.ignite.testframework.junits.GridAbstractTest in project ignite by apache.

the class IgniteTestSuite method addTestsFromTestCase.

/**
     *
     * @param theClass TestCase class
     */
private void addTestsFromTestCase(Class<?> theClass) {
    setName(theClass.getName());
    try {
        getTestConstructor(theClass);
    } catch (NoSuchMethodException ignored) {
        addTest(warning("Class " + theClass.getName() + " has no public constructor TestCase(String name) or TestCase()"));
        return;
    }
    if (!Modifier.isPublic(theClass.getModifiers()))
        addTest(warning("Class " + theClass.getName() + " is not public"));
    else {
        IgnoreDescriptor clsIgnore = IgnoreDescriptor.forClass(theClass);
        Class superCls = theClass;
        int testAdded = 0;
        int testSkipped = 0;
        LinkedList<Test> addedTests = new LinkedList<>();
        for (List<String> names = new ArrayList<>(); Test.class.isAssignableFrom(superCls); superCls = superCls.getSuperclass()) {
            Method[] methods = MethodSorter.getDeclaredMethods(superCls);
            for (Method each : methods) {
                AddResult res = addTestMethod(each, names, theClass, clsIgnore);
                if (res.added()) {
                    testAdded++;
                    addedTests.add(res.test());
                } else
                    testSkipped++;
            }
        }
        if (testAdded == 0 && testSkipped == 0)
            addTest(warning("No tests found in " + theClass.getName()));
        // Populate tests count.
        for (Test test : addedTests) {
            if (test instanceof GridAbstractTest) {
                GridAbstractTest test0 = (GridAbstractTest) test;
                test0.forceTestCount(addedTests.size());
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) LinkedList(java.util.LinkedList) GridAbstractTest(org.apache.ignite.testframework.junits.GridAbstractTest) GridAbstractTest(org.apache.ignite.testframework.junits.GridAbstractTest) Test(junit.framework.Test)

Aggregations

Test (junit.framework.Test)2 GridAbstractTest (org.apache.ignite.testframework.junits.GridAbstractTest)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1