Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing non-activity classes in Android

I know how to test Activity classes with JUnit 4 in Android but I am unable to understand how to test non-activity classes (which don't extends Activity, ListActivity, or some other Activity class, but uses some Android APIs). Please help me in this regard.

like image 972
Greenhorn Avatar asked Apr 29 '11 10:04

Greenhorn


1 Answers

To test non activity classes:

  1. create a test project
  2. create a test case
  3. run as Android JUnit Test

    public class MyClassTests extends TestCase {
    
    /**
     * @param name
     */
    public myClassTests(String name) {
        super(name);
    }
    
    /* (non-Javadoc)
     * @see junit.framework.TestCase#setUp()
     */
    protected void setUp() throws Exception {
        super.setUp();
                }
    
    /* (non-Javadoc)
     * @see junit.framework.TestCase#tearDown()
     */
    protected void tearDown() throws Exception {
        super.tearDown();
    }
    
    /**
     * Test something
     */
    public final void testSomething() {
                fail("Not implemented yet");
        }
    }
    
like image 119
Diego Torres Milano Avatar answered Sep 19 '22 20:09

Diego Torres Milano