Click here to load reader
Upload
dzugeek
View
213
Download
1
Embed Size (px)
Citation preview
Setting Up Android Mock in EclipseInitial Steps
To begin with, set up your Android project and test project in Eclipse as normal.
Download AndroidMockGenerator.jar and AndroidMockRuntime.jar from http://code.google.com/p/android-mock.
Add AndroidMockGenerator.jar as a Referenced Library in your Android test project.
Adding and Configuring the Annotation Processor1. Right click on your test project and select Properties.2. Choose Java Compiler and turn on Enable project specific settings. Ensure that the
Compiler compliance level is set to 1.6.
3. Choose Annotation Processing and turn on Enable project specific settings.4. Turn on Enable annotation processing.5. Turn off Enable processing in editor.6. Add a new Processor option (click New...) with key bin_dir and set the value to the
absolute path to your test project's bin folder (the folder set as the project's output folder).
7. Add another Processor option with key logfile and set the value to any location where you would like to log debug output from the Annotation processor. A good location for this is a file named AnnotationProcessor.log in your test project's base folder. This option is not required, but is highly recommended.
8. Choose Factory Path and select Add External JARs...9. Add AndroidMockGenerator.jar
10. Add the required class path entries by selecting Add Variable..., Configure Variables, New..., Name: (choose a name, any name), Path: (absolute path as appropriate).
a. Add a path entry for the (File...) Android runtime (android.jar). This should be the same jar file as the one the Eclipse automatically includes in your Android Project.
b. Add a path entry for the (Folder...) Android project's bin folder (the project being tested, not the test project).
c. Add additional path entries for any Jars in your Referenced Libraries which contain classes that your tests wish to Mock.
Checking that it all worked
The ultimate success test is to run your tests (using mocks) and see if they pass.
Other places to look for information about the mock generation are:
* Check under the test project's bin folder for a folder called genmocks. If you mock java.lang.Object (as a trivial example) a folder called genmocks/java/lang/ will be generated containing two classes which represent the mocks of java.lang.Object. * Check the output of the annotation processing in the log file which you specified by the Processor option in the instructions above (named logfile). This contains all of the output generated by a run of the Annotation Processor including any stack traces. Each execution will
start with a NOTE : Start Processing Annotations message and end with NOTE : Finished Processing Mocks. A single build may include multiple runs of the annotation processor.