7

Click here to load reader

Android Mock in Eclipse

  • Upload
    dzugeek

  • View
    213

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Android Mock in Eclipse

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.

Page 2: Android Mock in Eclipse

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.

Page 3: Android Mock in Eclipse

8. Choose Factory Path and select Add External JARs...9. Add AndroidMockGenerator.jar

Page 4: Android Mock in Eclipse

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.

Page 5: Android Mock in Eclipse
Page 6: Android Mock in Eclipse

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

Page 7: Android Mock in Eclipse

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.