如何从标准java代码调用android活动?

时间:2013-02-26 06:40:53

标签: java android robotium

这是我的示例测试项目,它使用robotium测试android计算器。 我想创建这个项目的jar文件,但在创建它时,它显示如下错误:

"Error: Could not find or load main class TestMain".

我认为它显示了这个错误,因为没有主要类别,即它找不到“public static void main(String args[])”。我该怎么做才能克服这个问题?

package com.testcalculator;

import com.jayway.android.robotium.solo.Solo;
import android.test.ActivityInstrumentationTestCase2;

@SuppressWarnings("unchecked")
public class TestCal extends ActivityInstrumentationTestCase2
{
    private static final String TARGET_PACKAGE_ID="com.calculator";
    private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME="com.calculator.Main";
    private static Class launcherActivityClass;
    static
    {
        try
        {
            launcherActivityClass=Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
        }
        catch (ClassNotFoundException e)
        {
            throw new RuntimeException(e);
        }
    }
    public TestCal()throws ClassNotFoundException
    {
        super(launcherActivityClass);
    }

    private Solo solo;

    @Override
    protected void setUp() throws Exception
    {
        solo = new Solo(getInstrumentation(),getActivity());
    }
    public void testDisplayBlackBox() 
    {
        solo.enterText(0, "10");

        solo.enterText(1, "20");

        solo.clickOnButton("Multiply");

        assertTrue(solo.searchText("200"));
    }
    @Override
    public void tearDown() throws Exception 
    {
        solo.finishOpenedActivities();
    }
}

0 个答案:

没有答案