Hi Gustav:
I'd recommend creating a second Android app project that contains your
tests, and add the original app project to the test project's build path.
As an example, lets say your existing app is called Foo. Do the following
steps:
1. Create a new Android Project called FooTest.
- Uncheck the Create Activity checkbox as it won't be needed
- Make sure you choose a unique package name for FooTest, that is
different than Foo's package
2. Add the Foo project to the FooTest project's build path. This can be
done via the following steps:
a. Select the FooTest project from the Eclipse Package Explorer
b. Select *File Properties*
c. Select *Java Build Path*
d. Select *Projects*
* *e. Select *Add*
f. Select Foo project
Now move your tests into FooTest. You should be able to run the tests that
do not reference any Android classes as a JUnit test. Make sure you select
the Android JUnit Test Launcher when prompted.
If you decide later on you want to add tests that do refer to Android
specific classes, Steve's suggestion is a good one - take a look at ApiDemos
and the ApiDemos tests. You'll want to ensure the following items are added
to the test's AndroidManifest.xml:
*application* **
* uses-library android:name=android.test.runner /*
*/application*
*
instrumentation
android:name=android.test.InstrumentationTestRunner
android:targetPackage=com.foo !-- this should be set to package
name of Foo project --
android:label=Tests for Foo/
*
You can run tests on an Android target by running the tests as a Android
JUnit Test. But note JUnit4 tests are currently not supported on the
Android platform.
I hope that helps. Please let me know if you need any clarification.
Regards,
Brett.
On Fri, Jun 5, 2009 at 9:22 AM, Steve steveoliv...@gmail.com wrote:
I've only dabbled in the JUnit with Android 1.5 so far, but I think
that if you take a look at the API Demos app you will see that they
have done exactly what you suggested (move the test classes into a
folder called tests).
I'm not on my dev machine right now so I can't confirm but I think you
also need to tweak the Android manifest. Again, the API Demos app has
a 2nd manifest so you can see how it's different from a production
manifest. (It's the instrumentation stuff, not sure if you need that
for JUnit but that's how they did it in the API Demos.)
One thing I've seen is that when you run the Eclipse project as an
Android JUnit app, it goes through its tests and reports in the JUnit
panel, and that's it (the app does not run in the emulator or on the
device). But if you run the apps as a regular Android app (not
JUnit), it skips the JUnit panel and you get the normal behavior
(loads to the device or emulator). What I'm not sure is -- and
hopefully someone else knows this -- when you build to the device,
does that mean it left all of your test classes out of the package?
On Jun 4, 4:00 pm, Parakoos parak...@gmail.com wrote:
Hello,
I am looking to add some JUnit4 tests to my android application. I am
going to test some classes that are totally decoupled from the Android
framework, so I don't want to involve the instrumentation bit. I will
be running these tests only from eclipse.
The question I have is how I can ensure that the test classes I write
will be excluded from the finished compiled program. After all, I
won't need them at that point. I'd like to keep all the 'real' java
packages in the default named source folder 'src' while I'd like all
my tests to be in a source folder named 'tst'.
Sorry if this is a stupid or simple question but after spending a
great deal of time searching for the answer I gave up!
Thanks,
Gustav
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---