I am trying to run a simple test with Robolectric in eclipse. I followed this tutorial, but got this error :
java.lang.RuntimeException: java.io.FileNotFoundException: C:\Vishal\Development\workspace>\AndroidHelloWorldTester.\AndroidManifest.xml not found or not a file; it >should point to your project's AndroidManifest.xml
Then as per Eugen's advice at here, I tried to extend the RobolectricTestRunner class as per instructed here but got this error :- (well I couldn't write the constructor exactly as directed since it was causing compilation error)
java.lang.Exception: Test class should have exactly one public zero-argument constructor
Currently this is the class :-
package com.myTest;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.model.InitializationError;
import android.widget.Button;
import android.widget.TextView;
import com.visd.helloworld.AndroidHelloWorldActivity;
import com.visd.helloworld.R;
import com.xtremelabs.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
public class Ahtest extends RobolectricTestRunner {
public Ahtest(Class AndroidHelloWorldActivity) throws InitializationError {
super(AndroidHelloWorldActivity, "<the project root location>");
// TODO Auto-generated constructor stub
}
private Button pressMeButton;
private TextView results;
AndroidHelloWorldActivity activity;
@Before
public void setUp() throws Exception {
activity = new AndroidHelloWorldActivity();
activity.onCreate(null);
pressMeButton = (Button) activity.findViewById(R.id.mybut1);
results = (TextView) activity.findViewById(R.id.text1);
}
@After
public void tearDown() throws Exception {
}
@Test
public void testSomethingMeaningfulToMyApp() {
pressMeButton.performClick();
String resultsText = results.getText().toString();
assertThat(resultsText, equalTo("Button Clicked"));
}
}
P.N. :
1) I made different project for the application and for the test.
2) I could not write the constructor exactly as specified since if I specified :-
super(testClass, new File("../other/project-root"));
I would get compilation error. Please help.