Re: [android-developers] ContentProvider contains dirty data from a previous JUnit test

2014-02-24 Thread Danny D
I haven't tested with the MockContentProvider, but I'm pretty sure that you 
just need to create one in the JUnit setup() routine and clear it in the 
teardown().  Make it a member of the JUnit class.  I saw several detailed posts 
after doing a Google search, have a look 
here:http://www.jayway.com/2011/10/10/using-renamingdelegatingcontext-to-mock-contentresolver-in-android/

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
Android Developers group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [android-developers] ContentProvider contains dirty data from a previous JUnit test

2014-02-23 Thread Danny D
As I read your reply, I'm confused now about what's being tested.  Are you 
testing the ContentProvider or the Activity?  If testing the Activity, it may 
be better to create a MockContentProvider that's responsible for providing back 
the info.  If testing the ContentProvider, skip the Activity and use an 
Application test case, as you get direct control of when its created or 
destroyed.

Sometimes its hard to do, but the goal in testing is to isolate the components 
and build known conditions around them.

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
Android Developers group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [android-developers] ContentProvider contains dirty data from a previous JUnit test

2014-02-23 Thread Code Guru
In this case, I am testing the activities of my app with
ActivityInstrumentationTestCase2. (I also have tests for the
ContentProvider using ProviderTestCase2.) The two tests that I outlined
earlier are for the data entry activity. I want to verify that the data
entered is inserted into the underlying database. The Activity inserts the
data via `getContentResolver.insert()`. The test case then opens the
database directly to assert that the data is there. How would I use a
MockContentProvider and/or other mock objects to perform this kind of
testing?

On Sun, Feb 23, 2014 at 12:29 PM, Danny D daniel.m.dev...@gmail.com wrote:

 As I read your reply, I'm confused now about what's being tested.  Are you
 testing the ContentProvider or the Activity?  If testing the Activity, it
 may be better to create a MockContentProvider that's responsible for
 providing back the info.  If testing the ContentProvider, skip the Activity
 and use an Application test case, as you get direct control of when its
 created or destroyed.

 Sometimes its hard to do, but the goal in testing is to isolate the
 components and build known conditions around them.

 --
 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
 ---
 You received this message because you are subscribed to a topic in the
 Google Groups Android Developers group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/android-developers/oOCF2V8tf90/unsubscribe
 .
 To unsubscribe from this group and all its topics, send an email to
 android-developers+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.




On Sun, Feb 23, 2014 at 12:29 PM, Danny D daniel.m.dev...@gmail.com wrote:

 As I read your reply, I'm confused now about what's being tested.  Are you
 testing the ContentProvider or the Activity?  If testing the Activity, it
 may be better to create a MockContentProvider that's responsible for
 providing back the info.  If testing the ContentProvider, skip the Activity
 and use an Application test case, as you get direct control of when its
 created or destroyed.

 Sometimes its hard to do, but the goal in testing is to isolate the
 components and build known conditions around them.

 --
 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
 ---
 You received this message because you are subscribed to a topic in the
 Google Groups Android Developers group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/android-developers/oOCF2V8tf90/unsubscribe
 .
 To unsubscribe from this group and all its topics, send an email to
 android-developers+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
Android Developers group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [android-developers] ContentProvider contains dirty data from a previous JUnit test

2014-02-23 Thread Kostya Vasilyev
I think you're seeing normal Unix (and Linux) file system semantics, with
respect to deleting a file that's currently open. This unlinks the name
from the underlying file system, but the file itself continues to stay
open, and has same content as before unlinking -- until the process that
has the file open terminates.

So, if you're going to execute both tests in one run, you need a way to
reset the database some other way.

One method would be to ensure that the CP closes the database before
deleting the files (then reopens).

Another would be to delete all data (DELETE FROM tablename).

Yet another would be to drop all tables (and to re-create them).

In any case, you'll need a way for your test code to trigger this code
inside the CP.

One way to do this would be to create a special purpose content:// URI and
call it from the test code (and the CP would recognize it and reset its
data using one of the methods above).

-- K



2014-02-24 1:33 GMT+04:00 Code Guru codegur...@gmail.com:

 In this case, I am testing the activities of my app with
 ActivityInstrumentationTestCase2. (I also have tests for the
 ContentProvider using ProviderTestCase2.) The two tests that I outlined
 earlier are for the data entry activity. I want to verify that the data
 entered is inserted into the underlying database. The Activity inserts the
 data via `getContentResolver.insert()`. The test case then opens the
 database directly to assert that the data is there. How would I use a
 MockContentProvider and/or other mock objects to perform this kind of
 testing?

 On Sun, Feb 23, 2014 at 12:29 PM, Danny D daniel.m.dev...@gmail.comwrote:

 As I read your reply, I'm confused now about what's being tested.  Are
 you testing the ContentProvider or the Activity?  If testing the Activity,
 it may be better to create a MockContentProvider that's responsible for
 providing back the info.  If testing the ContentProvider, skip the Activity
 and use an Application test case, as you get direct control of when its
 created or destroyed.

 Sometimes its hard to do, but the goal in testing is to isolate the
 components and build known conditions around them.

 --
 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
 ---
 You received this message because you are subscribed to a topic in the
 Google Groups Android Developers group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/android-developers/oOCF2V8tf90/unsubscribe
 .
 To unsubscribe from this group and all its topics, send an email to
 android-developers+unsubscr...@googlegroups.com.

 For more options, visit https://groups.google.com/groups/opt_out.




 On Sun, Feb 23, 2014 at 12:29 PM, Danny D daniel.m.dev...@gmail.comwrote:

 As I read your reply, I'm confused now about what's being tested.  Are
 you testing the ContentProvider or the Activity?  If testing the Activity,
 it may be better to create a MockContentProvider that's responsible for
 providing back the info.  If testing the ContentProvider, skip the Activity
 and use an Application test case, as you get direct control of when its
 created or destroyed.

 Sometimes its hard to do, but the goal in testing is to isolate the
 components and build known conditions around them.

 --
 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
 ---
 You received this message because you are subscribed to a topic in the
 Google Groups Android Developers group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/android-developers/oOCF2V8tf90/unsubscribe
 .
 To unsubscribe from this group and all its topics, send an email to
 android-developers+unsubscr...@googlegroups.com.

 For more options, visit https://groups.google.com/groups/opt_out.


  --
 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
 ---
 You received this message because you are subscribed to the Google Groups
 Android Developers group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to android-developers+unsubscr...@googlegroups.com.
 For more options, visit 

[android-developers] ContentProvider contains dirty data from a previous JUnit test

2014-02-22 Thread codeguru
Two of my JUnit tests against my app pass when I run them separately but 
fail when run consecutively.

The two tests run through the following sequence of actions:

*Test 1:*

   1. 
   
   Insert a single row to the database.
   
   This all occurs within the app using getContentResolver().insert().
   2. 
   
   Clean up the test.
   
   In particular, I delete the database using 
   context.deleteDatabase(DB_NAME);.
   
*Test 2:*

   1. 
   
   Insert multiple rows to the database.
   
   This again occurs within the app using multiple calls to 
   getContentResolver.insert(). The data inserted to the database includes 
   the data for the single row from Test 1. When this row of data is reached 
   in test 2, the test fails.
   
From what I can tell, the ContentProvider in Test 2 still sees the data 
added during Test 1. I suspect this is due to my method of cleaning up the 
test. I verified with adb shell that the database file is deleted when Test 
1 cleans up and that it is recreated when Test 2 starts.

How do I correctly clean up the first test so that the second test doesn't? 
I guess I could split the two test methods into two separate classes. Even 
if this works, it means that I will have to split up other classes with 
even more test methods that experience the same issue. Does anyone have 
other suggesions?

Code Guru

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
Android Developers group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[android-developers] ContentProvider contains dirty data from a previous JUnit test

2014-02-22 Thread Danny D
Is the object instance for the content provider different between test runs? 
How are you destroying and recreating the ContentProvider?

I suspect that if the Application instance is the same between test runs the 
ContentProvider might be too.  It's created at the Application level through 
the manifest, so you may need to use an ApplicationTestCase or something 
similar to be sure that the App instance is killed and restarted between tests.

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
Android Developers group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [android-developers] ContentProvider contains dirty data from a previous JUnit test

2014-02-22 Thread Code Guru
The `ContentProvider` is created indirectly by calling
`getContentResolver()` from inside a method of the `Activity` under test. I
will have to look into using `ApplicationTestCase` as you suggest.


On Sat, Feb 22, 2014 at 11:44 PM, Danny D daniel.m.dev...@gmail.com wrote:

 Is the object instance for the content provider different between test
 runs? How are you destroying and recreating the ContentProvider?

 I suspect that if the Application instance is the same between test runs
 the ContentProvider might be too.  It's created at the Application level
 through the manifest, so you may need to use an ApplicationTestCase or
 something similar to be sure that the App instance is killed and restarted
 between tests.

 --
 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
 ---
 You received this message because you are subscribed to a topic in the
 Google Groups Android Developers group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/android-developers/oOCF2V8tf90/unsubscribe
 .
 To unsubscribe from this group and all its topics, send an email to
 android-developers+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
Android Developers group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [android-developers] ContentProvider contains dirty data from a previous JUnit test

2014-02-22 Thread Code Guru
My current test class extends `ActivityInstrumentationTestCase2`. If I
change it to extend `ApplicationTestCase`, how do I start an activity?


On Sun, Feb 23, 2014 at 12:16 AM, Code Guru codegur...@gmail.com wrote:

 The `ContentProvider` is created indirectly by calling
 `getContentResolver()` from inside a method of the `Activity` under test. I
 will have to look into using `ApplicationTestCase` as you suggest.


 On Sat, Feb 22, 2014 at 11:44 PM, Danny D daniel.m.dev...@gmail.comwrote:

 Is the object instance for the content provider different between test
 runs? How are you destroying and recreating the ContentProvider?

 I suspect that if the Application instance is the same between test runs
 the ContentProvider might be too.  It's created at the Application level
 through the manifest, so you may need to use an ApplicationTestCase or
 something similar to be sure that the App instance is killed and restarted
 between tests.

 --
 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
 ---
 You received this message because you are subscribed to a topic in the
 Google Groups Android Developers group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/android-developers/oOCF2V8tf90/unsubscribe
 .
 To unsubscribe from this group and all its topics, send an email to
 android-developers+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
Android Developers group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.