FileDocCategorySizeDatePackage
TestCaseCollector.javaAPI DocAndroid 5.1 API5069Thu Mar 12 22:22:08 GMT 2015com.android.uiautomator.testrunner

TestCaseCollector

public class TestCaseCollector extends Object
A convenient class that encapsulates functions for adding test classes
hide

Fields Summary
private ClassLoader
mClassLoader
private List
mTestCases
private TestCaseFilter
mFilter
Constructors Summary
public TestCaseCollector(ClassLoader classLoader, TestCaseFilter filter)

        mClassLoader = classLoader;
        mTestCases = new ArrayList<TestCase>();
        mFilter = filter;
    
Methods Summary
protected voidaddSingleTestMethod(java.lang.Class clazz, java.lang.String method)

        if (!(mFilter.accept(clazz))) {
            throw new RuntimeException("Test class must be derived from UiAutomatorTestCase");
        }
        try {
            TestCase testCase = (TestCase) clazz.newInstance();
            testCase.setName(method);
            mTestCases.add(testCase);
        } catch (InstantiationException e) {
            mTestCases.add(error(clazz, "InstantiationException: could not instantiate " +
                    "test class. Class: " + clazz.getName()));
        } catch (IllegalAccessException e) {
            mTestCases.add(error(clazz, "IllegalAccessException: could not instantiate " +
                    "test class. Class: " + clazz.getName()));
        }
    
public voidaddTestClass(java.lang.String className)
Adds class to test by providing class name in string. The class name may be in "#" format

param
className classes must be subclass of {@link UiAutomatorTestCase}
throws
ClassNotFoundException

        int hashPos = className.indexOf('#");
        String methodName = null;
        if (hashPos != -1) {
            methodName = className.substring(hashPos + 1);
            className = className.substring(0, hashPos);
        }
        addTestClass(className, methodName);
    
public voidaddTestClass(java.lang.String className, java.lang.String methodName)
Adds class to test by providing class name and method name in separate strings

param
className class must be subclass of {@link UiAutomatorTestCase}
param
methodName may be null, in which case all "public void testNNN(void)" functions will be added
throws
ClassNotFoundException

        Class<?> clazz = mClassLoader.loadClass(className);
        if (methodName != null) {
            addSingleTestMethod(clazz, methodName);
        } else {
            Method[] methods = clazz.getMethods();
            for (Method method : methods) {
                if (mFilter.accept(method)) {
                    addSingleTestMethod(clazz, method.getName());
                }
            }
        }
    
public voidaddTestClasses(java.util.List classNames)
Adds classes to test by providing a list of class names in string The class name may be in "#" format

param
classNames class must be subclass of {@link UiAutomatorTestCase}
throws
ClassNotFoundException

        for (String className : classNames) {
            addTestClass(className);
        }
    
private UiAutomatorTestCaseerror(java.lang.Class clazz, java.lang.String message)

        UiAutomatorTestCase warning = new UiAutomatorTestCase() {
            protected void runTest() {
                fail(message);
            }
        };

        warning.setName(clazz.getName());
        return warning;
    
public java.util.ListgetTestCases()
Gets the list of added test cases so far

return
a list of {@link TestCase}

        return Collections.unmodifiableList(mTestCases);