The answer to your question can be found at
http://code.google.com/android/kb/troubleshooting.html#addjunit

Unfortunately, this is a bit unsatisfying. The way I understand this is that
while you can get JUnit to run on your host machine with this, it will not
have any access to any of the Android classes.

To test anything with Android classes in it (and that might be a innocuous
as 'Rect'), you will need to test on your emulator. The best way to get
testing rolling on the emulator is to follow the code examples given in the
sample directory from the Android SDK installation. The testing then works
from the command line. If someone knows how to get it working from within
Eclipse I would be grateful to hear this.

On a positive note: firewalling your application so that you have bits that
are completely Android unspecific and can thus be tested with JUnit
following the instructions from the link above, is probably a good idea as
it makes your code more portable. Then have code that is Android specific
that calls down into the generic code.

Ludwig



2008/10/12 dbanfield <[EMAIL PROTECTED]>

>
> It's been a while since this post but I will reply anyway. I've been
> scratching my head over this for the entire weekend. It's now come to
> my realisation that android release version 1 has been cut down to
> only include what will be the API. That is to say the jar file
> includes the  API and not the implementation of the API as such. This
> means that many objects will not contain an implementation -  hence
> the rather unhelpful "Stub!"  exception to indicate an access to a
> stub implementation. Within the emulator is a full implementation of
> the API. I'm still figuring out how to include this implementation in
> a project so that J. unit tests can run.
>
> On Sep 30, 1:41 am, elephantbug <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > After I migrate my code to 1.0, all my JUnit test cases throw
> > following exception, anyone can give me some clue:
> >
> > java.lang.RuntimeException: Stub!
> >         at
> > org.apache.http.params.AbstractHttpParams.<init>(AbstractHttpParams.java:
> > 5)
> >         at
> org.apache.http.params.BasicHttpParams.<init>(BasicHttpParams.java:
> > 6)
> >         at
> >
> com.loopt.network.HttpClientNetworkProvider.<init>(HttpClientNetworkProvider.java:
> > 39)
> >         at
> com.loopt.network.NetworkProvider.getInstance(NetworkProvider.java:
> > 65)
> >         at
> com.loopt.tests.network.BaseTestCase.setUp(BaseTestCase.java:43)
> >         at junit.framework.TestCase.runBare(TestCase.java:132)
> >         at junit.framework.TestResult$1.protect(TestResult.java:110)
> >         at junit.framework.TestResult.runProtected(TestResult.java:128)
> >         at junit.framework.TestResult.run(TestResult.java:113)
> >         at junit.framework.TestCase.run(TestCase.java:124)
> >         at junit.framework.TestSuite.runTest(TestSuite.java:232)
> >         at junit.framework.TestSuite.run(TestSuite.java:227)
> >         at
> >
> org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:
> > 130)
> >         at
> >
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:
> > 38)
> >         at
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:
> > 460)
> >         at
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:
> > 673)
> >         at
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:
> > 386)
> >         at
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:
> > 196)
> >
> > Here is the code snippet for the HttpClientNetworkProvider:
> >
> >                 HttpParams params = new
> > BasicHttpParams();                                //line 39:
> >                 ConnManagerParams.setMaxTotalConnections(params, 100);
> >                 HttpConnectionParams.setConnectionTimeout(params, 20 *
> 1000);
> >                 HttpProtocolParams.setVersion(params,
> HttpVersion.HTTP_1_1);
> >
> >                 // Create and initialize scheme registry
> >                 SchemeRegistry schemeRegistry = new SchemeRegistry();
> >                 schemeRegistry.register(new Scheme("http",
> > PlainSocketFactory.getSocketFactory(), 80));
> >                 schemeRegistry.register(new Scheme("https",
> > SSLSocketFactory.getSocketFactory(), 443));
> >
> >                 // Create an HttpClient with the
> ThreadSafeClientConnManager.
> >                 // This connection manager must be used if more than one
> thread will
> >                 // be using the HttpClient.
> >                 ClientConnectionManager cm = new
> ThreadSafeClientConnManager(params,
> > schemeRegistry);
> >
> >                 httpClient = new DefaultHttpClient(cm, params);
> >
> > Thanks.
> >
> > --elephantbug
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to