I want to be able to have two projects, one that contains production code and one that contains test code.
This shouldn't n开发者_开发知识库ecessarily be an Android-specific question, but I'm want to write some unit tests for some non-platform-specific Android code on the host PC.
I created a new Java project so I can run the unit tests on the PC and only include the non-platform-specific classes from the Android project. Both projects are opened in the same Eclipse workspace.
I assume I need to somehow include these Android-project sources explicitly in the new project where I'll run the Junit tests, but I can't figure out how to do this.
Thanks!
1) goto configure build path on the test project
2) in that dialog you will see a "tab" for "projects", click it
3) add the dependent project and click apply
If you add the project that contains the production code to the build path of the testing project then I imagine that should work. You can do this by right-clicking the testing project and selecting 'Build Path' > 'Configure Build Path', then going to the Projects tab and adding the production project.
Hopefully I understand what your intent is, but I believe there is exactly this feature for Android Development.
Using the Android Development Tools (ADT) for Eclipse, you should be able to create a new project of type "Android Test Project". You define the project, but also choose your existing project for the Test Target.
The test project will have special privileges when run in an emulator or on a device. It will be able to access all parts of the application as it will run in the same security context.
Also, have a look at Hello, Testing. Android provides quite a few testing utilities to get you started and save you from writing extra code.
精彩评论