doosungkang / android-daisy-epub-reader

Automatically exported from code.google.com/p/android-daisy-epub-reader
0 stars 0 forks source link

Decide whether to support running the unit tests on emulator / devices #10

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Currently the JUnit tests are simple JUnit 3 tests, which don't use the 
Android test runner. They currently rely on separate files e.g. sample 
books which are currently in the /Resources folder 
http://code.google.com/p/android-daisy-epub-
reader/source/browse/#svn/trunk/Resources The contents of this folder isn't 
exported or copied to the Emulator / Device by the Android test runner or 
the APK installation process. We need to decide whether to address this for 
the Android test runner, and if so, how? e.g. should we push the files to 
the emulator? should we move the resources to an embedded area of the 
project binary? (in the /res folder?)

What steps will reproduce the problem?
1. In eclipse try to run the tests as an Android JUnit Test
2. The application will be deployed to the emulator / device
3. However the tests will fail as the content of the /Resources folder 
isn't available.

The workaround (and the intended way to run the tests) is to use the 
standard JUnit test runner provided in eclipse.

What is the expected output? What do you see instead?

Please use labels and text to provide additional information.

Original issue reported on code.google.com by julianharty on 29 Dec 2009 at 5:48

GoogleCodeExporter commented 8 years ago
A quick update to remind me to investigate the following suggestion

http://stackoverflow.com/questions/3790963/android-how-to-transfer-a-test-fixtur
e-file-to-device-from-unit-test-application

In particular the following comment from Alex
If what you want to do is modify the path to the files the Activity you're 
testing uses, you should use !ActivityUnitTestCase and !setActivityContext() 
with a RenamingDelegatingContext. 
http://developer.android.com/reference/android/test/RenamingDelegatingContext.ht
ml This allows you to redirect file and database access in a context to a new 
directory by specifying a directory prefix. You can even use the more complex 
constructor to wrap the target context for most operations, but use your test 
application's context for file operations, so the activity will access files 
stored in the test application rather than the primary application but still 
use other resources in the primary application.

Original comment by julianharty on 18 Jan 2011 at 8:21

GoogleCodeExporter commented 8 years ago
Perhaps this will help too
http://stackoverflow.com/questions/2509429/android-pack-resources-into-apk

Original comment by julianharty on 3 Feb 2011 at 2:35

GoogleCodeExporter commented 8 years ago
I ended up establishing a consistent approach to referencing the test data used 
by the larger 'unit' tests. All the test data is relative to /sdcard/ e.g. 
/sdcard/Books/ for valid DAISY books. There are 3 sub-folders:
   * Books - for valid books which the app can also play 'normally'
   * problem content - which contains known abberations discovered in real DAISY books
   * testfiles - which are a small set of files for specific testing

The /sdcard/ folder can be created 'as-is' on Mac OS X and on linux machines. 
For Microsoft Windows it is treated as a root directory on the system drive 
(typically C:\sdcard\). Note: Windows (or more likely the Java runtime) copes 
with the / character as the directory separator and treats it like Windows' \ 
character.

When the tests are run using the ant scripts the pre-compile step in the 
build.xml for the App (not the one for the tests) copies the test data using 
`adb push` to the android device.

When the tests are run with the Eclipse junit test runner, they will fail 
unless you've first copied the contents of 
http://code.google.com/p/android-daisy-epub-reader/source/browse/#svn%2Ftrunk%2F
files-used-for-testing to /sdcard/ (or C:\sdcard on Windows machines)

There's still more scope to refine the tests e.g. to reduce the number of files 
copied; however since the tests do now run relatively well I'm marking this 
issue as 'fixed'.

Original comment by julianharty on 6 Jul 2012 at 7:03