Is it possible to write tests that delete ONLY the data they create?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Is it possible to write tests that delete ONLY the data they create?

JUnit - User mailing list
I'd like to be able to run some tests against fully populated QA databases. I can't find the right combination of set-up and tear-down to erase ALL the data created and inserted in the course of the test but not delete other data that preexists in the Db.
 

 Can this be done?
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible to write tests that delete ONLY the data they create?

JUnit - User mailing list
Hi,

Am 12.09.2016 um 17:59 schrieb [hidden email] [junit]:
>
> I'd like to be able to run some tests against fully populated QA databases. I
>  can't find the right combination of set-up and tear-down to erase ALL the data
>  created and inserted in the course of the test but not delete other data that
>  preexists in the Db.

Create a new database/scheme and copy all data from the QA-database to your
new one. After the test, simply delete the database/scheme.

Another solution is to use virtualization. Fire up a guest that is
configured to be rolled back to the state it was before when shut down.


Cheers, Lothar
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible to write tests that delete ONLY the data they create?

JUnit - User mailing list
In reply to this post by JUnit - User mailing list
There is no simple, general answer to this question. Some ideas that come
to mind... In the order which I would try first.
Maybe you can address the problem on the infrastracture-level, as Lothar
suggested. (Copy the DB etc.)
Mechanisms like Docker-Container might help here, too!
You might be able to execute your tests in a transaction, which is then
rolled back at the end of the test.
You may be able to just add testdata to the DB and don't worry about it,
since it does not harm other tests.
You may be able to separate all new testdata from the data that is present,
so that you can remove it safely (i.e. IDs in certain ranges etc.)
And if all else fails, I also reacted a mechanism in a project before, that
remembered all the test data created during a test and removed it
individually in a teardown, but that's a lot of work and rather fragile.
Not really recommended.

Greetings,
   Malte

On 12 September 2016 at 17:59, [hidden email] [junit] <
[hidden email]> wrote:

>
>
> I'd like to be able to run some tests against fully populated QA
> databases. I can't find the right combination of set-up and tear-down to
> erase ALL the data created and inserted in the course of the test but not
> delete other data that preexists in the Db.
>
>
> Can this be done?
>
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible to write tests that delete ONLY the data they create?

JUnit - User mailing list
In reply to this post by JUnit - User mailing list


 I think you should focus on setUp, instead of tearDown. The absolute best longterm solution (in my opinion) is to let every test be responsible for setting up its own data. If you succeed with that, you can simply wipe the data store (or even create it from scratch) before each test.
 This may require some work if your existing tests are dependent on existing data, but more often than not it's totally worth it. In the process you will discover (and document) what is needed to create the data in your data store.  
 Most importantly, the data in your "fully populated QA database" is probably created using a version (or many difversions) of your program that is not current. This may cause all kinds of problems. Having each test create all its data solves this situation perfectly.    
 

 

 
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible to write tests that delete ONLY the data they create?

JUnit - User mailing list
I totally agree.

One sidenote: We also remove Data in our setup-methods and not in our
teardowns. So every test makes sure that there is no data laying around
that would hinder it's exeution before it is executed. Our experience is,
that this is more robust.

Greetings,
   Malte

On 14 September 2016 at 14:14, [hidden email] [junit] <
[hidden email]> wrote:

>
>
>
> I think you should focus on setUp, instead of tearDown. The absolute best
> longterm solution (in my opinion) is to let every test be responsible for
> setting up its own data. If you succeed with that, you can simply wipe the
> data store (or even create it from scratch) before each test.
> This may require some work if your existing tests are dependent on
> existing data, but more often than not it's totally worth it. In the
> process you will discover (and document) what is needed to create the data
> in your data store.
> Most importantly, the data in your "fully populated QA database" is
> probably created using a version (or many difversions) of your program that
> is not current. This may cause all kinds of problems. Having each test
> create all its data solves this situation perfectly.
>
>
>
>
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible to write tests that delete ONLY the data they create?

JUnit - User mailing list
In reply to this post by JUnit - User mailing list
Thanks for all the replies. 
I see the way forward. CLEAN_INSERT and DELETE_ALL  with a Db that has no data in it. 

 Lowell Gilbertson lowellgilbertson dot com