Comments below.
On Tue, Sep 8, 2009 at 1:12 AM, [email protected]
<[email protected]> wrote:
>
> Hi, i am having two issues when doing Junit testing on my code. the
> first issue is i cant seem to unit test a private method or class and
> was wondering if its possible to do so.
No its not possible. The same access rules that apply to application
code will apply to test code.
>
> the second issue is that i have setup a seperate android project for
> doing all the testing and have just added the main project into its
> build path so i can call methods from the main android project i am
> testing on. Whenever i call something from the main project ie Myclass
> myclass = new Myclass(); it fails saying that the Test Run failed with
> a java.lang.Verify error
I believe one cause of VerifyError is that the class you are trying to
load is not in the current process's runtime classpath. In order for
your test app to be able to access the main app's classes at runtime,
you need to specify a instrumentation tag in your test app's
AndroidManifest.xml. Ensure the "targetPackage" is set to the main
application package.
See the samples/ApiDemos/tests/AndroidManifest.xml for an example. ie
<!--
This declares that this app uses the instrumentation test runner targeting
the package of com.example.android.apis. To run the tests use the command:
"adb shell am instrument -w
com.example.android.apis.tests/android.test.InstrumentationTestRunner"
-->
<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.example.android.apis"
android:label="Tests for Api Demos."/>
>
> i am simply creating a new class object from my main project into my
> AndroidTestCase class so im not quite sure what the issue is.
>
> i am basicly having the exact same issue as someone in this link
> http://dtmilano.blogspot.com/2009/07/android-testing-on-android-platform_4442.html
> who has posted a comment about it
>
> Here below is the original comment made by someone with the same issue
> i have.
>
> [quote]
>
> hey diego, i'm trying to create a unit test by following your
> tutorial. I've arrived in which i created a test method for one of my
> class (called MyClass for example) which resides in my main package
> (say, com.package.main). And yes, I've put my main project in the test
> build path configuration.
>
> And then, I tried to create the class in one of my test case in a
> usual manner of:
>
> MyClass myClass = new MyClass()
>
> And then I tried to run the test project and it always gives Test run
> failed messages. This happens eveytime I wanted to instantiate any
> class that resides in my main project. Can you help me on this? Thanks
> in advance :).
>
> [/quote]
>
> Anyways, thanks for your time in reading this and im hoping someone
> here can help me as i really want to create a seperate project with
> all my Testcase's and TestSuits instead of including them in the main
> project. I also do not want to make my private class and methods
> public just for Unit testing.
>
> Thanks again and looking forward to some of your advice.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---