私は現在、メインの Android アプリケーションに対してテストする Eclipse ADT の Robolectrics を使用したテスト プロジェクトに取り組んでいます。Junit 4 を使用していますが、動作させることができません。誰かが私のコードの間違いを指摘できますか? コードは次のとおりです。私はそれに本当に苦労しています。エラートレースは次のとおりです。
java.lang.RuntimeException: java.lang.NumberFormatException: For input string: "FFFFFF
"
at com.xtremelabs.robolectric.res.ResourceLoader.init(ResourceLoader.java:148)
at com.xtremelabs.robolectric.res.ResourceLoader.setLayoutQualifierSearchPath(ResourceLoader.java:506)
at com.xtremelabs.robolectric.RobolectricTestRunner.setupApplicationState(RobolectricTestRunner.java:362)
at com.xtremelabs.robolectric.RobolectricTestRunner.internalBeforeTest(RobolectricTestRunner.java:307)
at com.xtremelabs.robolectric.RobolectricTestRunner.methodBlock(RobolectricTestRunner.java:285)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.NumberFormatException: For input string: "FFFFFF
"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Long.parseLong(Unknown Source)
at com.xtremelabs.robolectric.res.ColorResourceLoader.convertRawValue(ColorResourceLoader.java:44)
at com.xtremelabs.robolectric.res.ColorResourceLoader.convertRawValue(ColorResourceLoader.java:9)
at com.xtremelabs.robolectric.res.ResourceReferenceResolver.processResource(ResourceReferenceResolver.java:29)
at com.xtremelabs.robolectric.res.ColorResourceLoader.processNode(ColorResourceLoader.java:38)
at com.xtremelabs.robolectric.res.XpathResourceXmlLoader.processResourceXml(XpathResourceXmlLoader.java:27)
at com.xtremelabs.robolectric.res.DocumentLoader.loadResourceXmlFile(DocumentLoader.java:58)
at com.xtremelabs.robolectric.res.DocumentLoader.loadResourceXmlDir(DocumentLoader.java:52)
at com.xtremelabs.robolectric.res.DocumentLoader.loadResourceXmlDir(DocumentLoader.java:39)
at com.xtremelabs.robolectric.res.ResourceLoader.loadValueResourcesFromDir(ResourceLoader.java:233)
at com.xtremelabs.robolectric.res.ResourceLoader.loadValueResourcesFromDirs(ResourceLoader.java:227)
at com.xtremelabs.robolectric.res.ResourceLoader.loadValueResources(ResourceLoader.java:170)
at com.xtremelabs.robolectric.res.ResourceLoader.init(ResourceLoader.java:132)
... 19 more
@RunWith(CustomTestRunner.class)
public class AccessActivity_Test{
private AccessActivity activity;
private Button signup;
private Button signupwithFB;
@Before
public void setUp() {
activity = new AccessActivity();
activity.onCreate(null);
//MockitoAnnotations.initMocks(this);
//FrameLayout layout = (FrameLayout) activity.findViewById(R.layout.access_main);
signup= (Button)activity.findViewById(R.id.btn_signup);
signupwithFB = (Button) activity.findViewById(R.id.btn_signupFB);
//frag = Robolectric.shadowOf(activity.getSupportFragmentManager().findFragmentById(R.id.container));
}
@After
public void tearDown() {
}
@Test
public void TestSignUpButton()throws Exception{
signup.performClick();
}
@Test
public void TestSignUpWithFBButton(){
signupwithFB.performClick();
}
カスタム TestRunner は次のとおりです。
public class CustomTestRunner extends RobolectricTestRunner {
public CustomTestRunner(Class<?> testClass) throws InitializationError {
super(testClass);
addClassOrPackageToInstrument("com.actionbarsherlock.app.SherlockActivity");
addClassOrPackageToInstrument("com.actionbarsherlock.app.SherlockFragmentActivity");
}
@Override
protected void bindShadowClasses() {
super.bindShadowClasses();
Robolectric.bindShadowClass(ShadowSherlockActivity.class);
Robolectric.bindShadowClass(ShadowSherlockFragmentActivity.class);
}
}
アクティビティは次のとおりです。
public class AccessActivity extends RoboSherlockFragmentActivity {
private static final String STATE_SELECTED_NAVIGATION_ITEM = "selected_navigation_item";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.access_main);
// Set up the action bar.
getSupportActionBar().show();
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, new AccessOptionsFragment())
.commit();
}
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
if (savedInstanceState.containsKey(STATE_SELECTED_NAVIGATION_ITEM)) {
getSupportActionBar().setSelectedNavigationItem(
savedInstanceState.getInt(STATE_SELECTED_NAVIGATION_ITEM));
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putInt(STATE_SELECTED_NAVIGATION_ITEM,
getSupportActionBar().getSelectedNavigationIndex());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
return true;
}
}
フラグメントのコードは次のとおりです。
public class AccessOptionsFragment extends RoboSherlockFragment implements
AnimationListener, OnClickListener {
// @InjectView(tag = "logo_layout")
// LinearLayout logo_layout;
// @InjectView(tag = "signup_layout")
// LinearLayout signup_layout;
//result codes if other than standard
//@InjectView(tag = "signup_layout")LinearLayout signup_layout;
public final static int LOGIN_REQUESTED = 1;
public final static int SIGNUP_REQUESTED = 2;
public final static int SIGNUPFB_REQUESTED = 3;
public final static int SKIPACCESS_REQUESTED = 4;
private Animation fadeInAnimation;
.....
..
誰かが私にどこが間違っているかのヒントを教えてもらえますか? または、誰かがより良いアイデアを持っていますか?
事前に助けてくれてありがとう。