Elvenware

Table of Contents

Toggle Menu

Charlie Calvert on Elvenware

Writing Code and Prose on Computers

Core Code

OS and Tools

Art

Elvenware
Elvenware

Unit Testing

Create a project that you want to test.

Creating a unit test project
Creating a unit test project

Figure 01: Creating an Android Test Project

Name your project
Name your project

Figure 02: Name your project

Select the project you want to test
Select the project you want to test

Figure 03: Select the project you want to test.

Select build target
Select build target

Figure 04: Select your build target.

Create a test class
Create a test class

Figure 04: Create your test class.

package com.elvenware.walking.test;

import android.test.ActivityInstrumentationTestCase2;
import com.elvenware.walking.LearningManActivity;

public class BasicTests extends ActivityInstrumentationTestCase2<LearningManActivity>
{
    public BasicTests()
    {
        super("com.elvenware.walking", LearningManActivity.class);
    }
}

Listing 1: Setting up your unit test.

package com.elvenware.walking.test;

import android.test.ActivityInstrumentationTestCase2;
import com.elvenware.walking.LearningManActivity;

public class BasicTests extends ActivityInstrumentationTestCase2
{
    private LearningManActivity mActivity;

    public BasicTests()
    {
        super("com.elvenware.walking", LearningManActivity.class);
    }

    @Override
    protected void setUp() throws Exception 
    {
        super.setUp();
        mActivity = this.getActivity();
    }

    public void testText() 
    {
        assertEquals("Eduction and learning",
            (String)mActivity.getText(com.elvenware.walking.R.string.hello));
    }
}

Listing 2: A complete test

Hello, Testing

Copyright © Charlie Calvert | Elvenware Home | Writing Code | Delphi | CSharp | My Books