我是 Android 上 JUnit 和 FEST 的新手。我正在尝试在课堂上使用FEST-Android,但在编译时不断出错:
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
到目前为止,没有 FEST 库,我在创建一个简单的类方面取得了一些成功,如下所示。
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));
}
}
一旦我使用 Maven 将 FEST-Android 库包含到测试项目中,错误就会出现(我不熟悉 Maven,但直接下载 jar 对我来说是关闭的)。
这是 FEST-Android 1.0.1 包内的内容
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
我需要删除一些东西吗?我的项目使用 ActionBarSherlock,为了让 JUnit 工作,我还需要导出项目使用的所有库。