arquillian / arquillian-extension-persistence

Arquillian Database / Persistence Extension

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Execute scripts before test starts

FagnerMartinsBrack opened this issue · comments

I use the option to execute scripts before and after each test case with postgres (drop all tables and then create all tables with some default data, in that order).

Sometimes the script fails and the build stops. Ok, that is expected and useful.

The thing is that my database stays "dirty" because the whole script file failed to execute properly. Then when I correct it and try to run the tests again it pops up an unexpected error, which is "table x already exists" when trying to create the initial tables (it assumes the database is clean at the start)

The way I see to solve this is to allow an "init" option to execute a given script before the whole test starts (not in a given class because its order can change).

Any thoughs? Is there already an API for this?

Which database are you using? Some of them have handy features like "drop if exists" which makes your initial scripts nicely repeatable.

Again - I strongly recommend to raise such concerns on Arquillian Forum :)

You misunderstood my issue. I am using postgres but this is irrelevant.
There is no such feature in APE as execute a script when the whole test suite starts (or at least this is not documented)
No simple SQL solution will solve my issue, or it will be too verbose (like dropping tables in the create script instead of separate such concerns)

My apologies, I misread :) There is @CreateSchema annotation which runs only once for the given test class or @ApplyScriptBefore for each test. Is that what you are looking for?

Yes I am using that, but the thing is I cannot execute once before the whole test suite is started.

Lets take the following use case as an example:

  • Use @ApplyScriptBefore to create all tables.
  • Use @ApplyScriptAfter to drop all tables.
  • If the SQL has syntax errors, the tests stop and several tables are not droped (@ApplyScriptAfter is not executed).
  • Then I have to manually drop the tables from my DB management tool to make the tests work correctly.

In general (so outside of APE realm) relying on "after-test" fixture clean up is not really reliable solution. I always do "drop-if-exists+create" before the test. The same when it comes to dbunit - clean tables before the test and apply test data, not apply test data first and then clean after the test, as "after test" might not be reached.

I totally forgot this issue.

Anyway, if it is not a reliable solution to clear the schema upon "after-test" so what is the purpose of the feature?
I just assumed to be an obvious bug since I was hoping APE could handle such case or at least provide an API to do so. IMO It is natural to intuitively suppose the "after test" is meant for database clean-up since then we would not leave behind any junk.
I followed your workaround though and used the scripts in the @ApplyScriptBefore.

Another thing I noticed regarding this project:
It seems you are using JIRA for tracking issues, JBoss forum for questions and github for pull requests. So why are the issues open here?
I am actively on Github due to other projects that are hosted only here and I keep track too.
Since the issues are available, I assumed it should be used, that is why I posted here.

I'm not an owner of this repository, therefore I can't change the settings.

Issues removed :)