Question

I'm new to both JUnit and FEST on Android. I'm trying to use FEST-Android in my class but keep getting error when compile:

Android Dex: [ZHoltoTest] trouble processing "javax/xml/parsers/DocumentBuilder.class":
Android Dex: [ZHoltoTest] Ill-advised or mistaken usage of a core class (java.* or javax.*)
Android Dex: [ZHoltoTest] when not building a core library.
Android Dex: [ZHoltoTest] This is often due to inadvertently including a core library file

So far, without FEST library, I have somewhat success in creating a simple class as following.

package com.monster.beta.tests;

import android.graphics.Rect;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.Button;
import com.monster.beta.R;
import com.monster.beta.activity.WelcomeActivity;

public class WelcomeActivityTest extends ActivityInstrumentationTestCase2<WelcomeActivity> {
    WelcomeActivity activity;
    public WelcomeActivityTest() {
        super("com.monster.beta", WelcomeActivity.class);

    }
    protected void setUp() throws Exception {
        super.setUp();
        activity = getActivity();
    }

    public void testCloseWording(){
        Button btnSync = (Button) activity.findViewById(R.id.btnClose);

        assertTrue("Text is<" + btnSync.getText().toString() + "> expect<close me>", "close me".equalsIgnoreCase(btnSync.getText().toString()));
    }

    public void testCloseBtn(){
        Button btnSync = (Button) activity.findViewById(R.id.btnClose);
        btnSync.callOnClick();

        int btnSyncLoc[] = new int[2];
        btnSync.getLocationOnScreen(btnSyncLoc);

        Rect btnRect = new Rect();
        btnSync.getDrawingRect(btnRect);

        assertTrue("btnSyncLoc is<" + btnSyncLoc[0] + "> not less than hundred", (btnSyncLoc[0] < 100));
    }

    public void testCloseBtn2(){
        Button btnSync = (Button) activity.findViewById(R.id.btnClose);

        int btnSyncLoc[] = new int[2];
        btnSync.getLocationOnScreen(btnSyncLoc);

        Rect btnRect = new Rect();
        btnSync.getDrawingRect(btnRect);

        assertTrue("btnSyncLoc is<" + btnSyncLoc[1] + "> not less than hundred", (btnSyncLoc[1] < 100));
    }

}

The error show up as soon as I include FEST-Android library into the test project using Maven (I'm not familiar with Maven but the direct download jar was down for me).

Here is the content inside FEST-Android 1.0.1 package

C:\Users\poohdish.SPHINXPARTNERS\git\FEST-Android\android-4.1.1.4.jar
C:\Users\poohdish.SPHINXPARTNERS\git\FEST-Android\commons-codec-1.3.jar
C:\Users\poohdish.SPHINXPARTNERS\git\FEST-Android\commons-logging-1.1.1.jar
C:\Users\poohdish.SPHINXPARTNERS\git\FEST-Android\fest-android-1.0.1.jar
C:\Users\poohdish.SPHINXPARTNERS\git\FEST-Android\fest-assert-core-2.0M8.jar
C:\Users\poohdish.SPHINXPARTNERS\git\FEST-Android\fest-util-1.2.3.jar
C:\Users\poohdish.SPHINXPARTNERS\git\FEST-Android\httpclient-4.0.1.jar
C:\Users\poohdish.SPHINXPARTNERS\git\FEST-Android\httpcore-4.0.1.jar
C:\Users\poohdish.SPHINXPARTNERS\git\FEST-Android\json-20080701.jar
C:\Users\poohdish.SPHINXPARTNERS\git\FEST-Android\opengl-api-gl1.1-android-2.1_r1.jar
C:\Users\poohdish.SPHINXPARTNERS\git\FEST-Android\support-v4-r7.jar
C:\Users\poohdish.SPHINXPARTNERS\git\FEST-Android\xmlParserAPIs-2.6.2.jar
C:\Users\poohdish.SPHINXPARTNERS\git\FEST-Android\xpp3-1.1.4c.jar

Do I need to remove something? My project uses ActionBarSherlock and to make JUnit work I need to export all the library used by the project as well.

Was it helpful?

Solution

You are trying to add core java class to android application. Do not do this. You do not need XML APIs on your classpath. The Android jar contains all the XML APIs you are going to need there.

I dare say that the only library from the list that needs to be packaged is android-support-v4

Also, if you are working with eclipse, keep in mind that it has only one classpath scope. There is no separate scope for testing.

OTHER TIPS

From https://github.com/square/fest-android

grab via Maven:

<dependency>
  <groupId>com.squareup</groupId>
  <artifactId>fest-android</artifactId>
  <version>1.0.1</version>
</dependency>

add this into pom.xml of you test project.

You don't need to export or import libraries using Eclipse, as maven and m2e will do it for you, when you define wha you need. Maven (m2e) will download all required jars.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top