Android TestCase - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android TestCase class.

This code example shows how to use the following methods:getClass, getName
            if (test instanceof TestCase) {
                TestCase testCase = (TestCase) test;
                checkForNewSuite(testCase);
                mSerializer.startTag("", TAG_CASE);
                mSerializer.attribute("", ATTRIBUTE_CLASS, mCurrentSuite);
                mSerializer.attribute("", ATTRIBUTE_NAME, testCase.getName());
 
                mTimeAlreadyWritten = false;
                mTestStartTime = System.currentTimeMillis();
            } 
        } catch (IOException e) {
            Log.e(LOG_TAG, safeMessage(e));
        } 
    } 
 
    private void checkForNewSuite(TestCase testCase) throws IOException {
        String suiteName = testCase.getClass().getName();
        if (mCurrentSuite == null || !mCurrentSuite.equals(suiteName)) {
            if (mCurrentSuite != null) {
                if (mMultiFile) {

7
CodeRank
This code example shows how to use the following methods:getClass, getName
			testKeeper.setTestname(testName);
			mTimeAlreadyWritten = false;
			mTestStartTime = System.currentTimeMillis();
			testKeeper.setStartTime(mTestStartTime);
			currentSuite.setStartTime(System.currentTimeMillis());
			testKeeper.setTest(testCase);
			checkSuiteDetails(test);
			addToSuite(test, testKeeper);
		} 
	} 
 
	private void addToSuite(Test test, TestKeeper testKeeper) {
		TestCase testcase = (TestCase) test;
		String suiteName = testcase.getClass().getName();
		HashMap<String, TestKeeper> suiteTests;
		if (suiteMap.containsKey(suiteName)) {
			suiteTests = suiteMap.get(suiteName);
		} else { 
			suiteTests = new HashMap<String, TestKeeper>();
		} 

6
CodeRank
This code example shows how to use the following methods:getClass, run
 
        while (fTests.size() != 0 && !result.shouldStop()) {
            TestCase test = (TestCase)fTests.elementAt(i);
             
            Thread.currentThread().setContextClassLoader(
                    test.getClass().getClassLoader());
 
            test.run(result);
 
            /* 
            if (fVictim != null) { 
                TestResult dummy = fVictim.run(); 
 
                if (dummy.failureCount() != 0) { 
                    result.addError(fTests.elementAt(i), new RuntimeException( 
                            "Probable side effect", 
                            ((TestFailure)dummy.failures().nextElement()). 
                            thrownException())); 
                } else if (dummy.errorCount() != 0) { 
                    result.addError(fTests.elementAt(i), new RuntimeException( 
5
CodeRank
This code example shows how to use the following methods:run, setName
            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 {

5
CodeRank
This code example shows how to use the following methods:getClass, getName
     * Checks whether the given TestCase method has the given annotation. 
     */ 
    @SuppressWarnings("unchecked") 
    boolean hasAnnotation(TestCase test, Class clazz) {
        try { 
            Method method = test.getClass().getMethod(test.getName());
            return method.getAnnotation(clazz) != null;
        } catch (Exception e) {
            // Ignore 
        } 
 
        return false; 
    } 
 
    @Override 
    @SuppressWarnings("deprecation") 
    public void runProtected(final Test test, Protectable p) {
        if ((fFlags & CoreTestSuite.DRY_RUN) == 0) {
            if (test instanceof TestCase) {
                TestCase testCase = (TestCase)test;
5
CodeRank
This code example shows how to use the following methods:run, setName
		assertEquals("tests are being not being ran by JUnit", 3, result.runCount());
		assertEquals("skipped tests not properly recorded", 2, ConditionalTestCase.getDisabledTestCount());
	} 
 
	private void executeTest(String testMethod) {
		test.setName(testMethod);
		test.run(result);
	} 
} 
5
CodeRank
This code example shows how to use the following methods:getName
    private int bugNum = -1;
     
    public FailingTest( TestCase test, int bugNumber ){
        this.test = test;
        this.bugNum = bugNumber;
        String name= "Failing " + test.getName();
        if (bugNum > 0) {
        	name += " [bug " + bugNum + "]";
        } 
        setName(name);
    } 
     
    public FailingTest( TestCase test ){
        this(test, -1);
    } 
    /* (non-Javadoc) 
     * @see junit.framework.Test#run(junit.framework.TestResult) 
     */ 
    public void run( TestResult result ) {
        result.startTest( this );
5
CodeRank
This code example shows how to use the following methods:run
     
    /** Bootstrap for the self-test code. 
     */ 
    public static void main( String[] argc ) throws Exception {
        TestCase test = new JspTaglibsTest( "test-jsptaglibs.txt" );
        test.run();
    } 
} 
5
CodeRank
This code example shows how to use the following methods:getClass, run
         
        while (fTests.size() != 0 && !result.shouldStop()) {
            TestCase test = (TestCase)fTests.elementAt(i);
             
            Thread.currentThread().setContextClassLoader(
                    test.getClass().getClassLoader());
             
            test.run(result);
 
            /* 
            if (fVictim != null) { 
                TestResult dummy = fVictim.run(); 
                 
                if (dummy.failureCount() != 0) { 
                    result.addError(fTests.elementAt(i), new RuntimeException( 
                            "Probable side effect",   
                            ((TestFailure)dummy.failures().nextElement()). 
                            thrownException())); 
                } else if (dummy.errorCount() != 0) { 
                    result.addError(fTests.elementAt(i), new RuntimeException( 
5
CodeRank
This code example shows how to use the following methods:getName

Related Android TestCase Questions & Answers:

See Code Examples for Android TestCase Methods: