I'm writing testcases for an android app extending ActivityInstrumentationTestCase2
. The test class looks like this:
public class SolutionEntryActivityTest extends ActivityInstrumentationTestCase2<SolutionEntryActivity> {
public SolutionEntryActivityTest() {
super(SolutionEntryActivity.class);
}
}
In eclipse, this code fails to compile with the error: Bound mismatch: The type SolutionEntryActivity is not a valid substitute for the bounded parameter <T extends Activity> of the type ActivityInstrumentationTestCase2<T>
But SolutionEntryActivity really is an android.app.Activity
, the type hierarchy is like this:
Activity
OrmLiteBaseActivity<H> (abstract)
KabowieActivity
PracticeActivity (abstract)
SolutionEntryActivity
I found two eclipse bugs from 2004 and 2005 which seem to deal with a similar problem but these should be long fixed.
I'm using Eclipse Helios with Android 2.2 and Sun Java 1.6.
Any idea what's going on?
The problem was that when you create a test project with the android eclipse project, references from the project-to-be-tested to external libraries are not resolved automatically. The class OrmLiteBaseActivity (see type hierarchy in the originial question) comes from an external jar included in the build path of the project under test. That external jar needs to be explicitely included in the build path of the test project as well. Not sure if this could be considered a bug and if so, where. But I would expect that all libraries used by the original project should also be available to the test project. Anyway, thanks to those who read the question.
EDIT Correction: adding the same library to the buildpath twice (once to the one of the project under test, and once to the testproject) does not work because JUnit does not understand that both are really the same library. Compilation will succeed but LogCat will give an error message saying that the superclasses of the SolutionEntryActivity are from different sources. The solution here is to export external libs from the original project (Configure buildpath -> Order and export -> select libs to be exported) instead of adding them to the buildpath of the test project directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With