Code example for TestCase

Methods: runsetName

0
            if (mTestCase instanceof DeviceTest) {
                DeviceTest deviceTest = (DeviceTest) mTestCase;
                deviceTest.setDevice(mTest.mDevice.getDevice());
                deviceTest.setTestAppPath(HostConfig.getInstance().getCaseRepository().getRoot());
            } 
            mTestCase.run(result);
        } 
        return result;
    } 
 
    /** 
     * Load test case via test class name and test method. 
     * 
     * @param testClassName The class name. 
     * @param testMethodName The method name. 
     */ 
    @SuppressWarnings("unchecked") 
    public TestCase loadTestCase(final String jarPath,
            final String testPkgName, final String testClassName,
            final String testMethodName) throws ClassNotFoundException, IOException {
 
        Log.d("jarPath=" + jarPath + ",testPkgName=" + testPkgName
                + ",testClassName=" + testClassName);
 
        Class testClass = null;
        if ((jarPath != null) && (jarPath.endsWith(JAR_SUFFIX))) {
            testClass = loadClass(jarPath, testPkgName, testClassName);
        } else { 
            testClass = Class.forName(testPkgName + "." + testClassName);
        } 
 
        if ((testMethodName != null) && TestCase.class.isAssignableFrom(testClass)) {
            mTestCase = buildTestMethod(testClass, testMethodName);
        } 
 
        return mTestCase;
    } 
 
    /** 
     * Load class from jar file. 
     * 
     * @param jarPath The jar file. 
     * @param testPkgName The package name. 
     * @param testClassName The class name. 
     * @return The class. 
     */ 
    @SuppressWarnings("unchecked") 
    public Class loadClass(final String jarPath,
            final String testPkgName, final String testClassName)
            throws ClassNotFoundException, IOException { 
 
        URL urls[] = { new File(jarPath).getCanonicalFile().toURI().toURL() };
        URLClassLoader cl = new URLClassLoader(urls);
        Class testClass = cl.loadClass(testPkgName + "." + testClassName);
        Log.d("succeed in load jarred class: " + jarPath + "." + testPkgName
                + "." + testClassName);
 
        return testClass;
    } 
 
    /** 
     * Build test method. 
     * 
     * @param testClass The test class. 
     * @param testMethodName The method name. 
     * @return The test case. 
     */ 
    @SuppressWarnings("unchecked") 
    private TestCase buildTestMethod(Class testClass,
            String testMethodName) {
        try { 
            TestCase testCase = (TestCase) testClass.newInstance();
            testCase.setName(testMethodName);
            return testCase;
        } catch (IllegalAccessException e) {
            runFailed("Could not access test class. Class: " 
                    + testClass.getName());
        } catch (InstantiationException e) {
Contextual code suggestions in your IDE  Get Codota for Java