I just tried ScalaTest 1.5.RC2 (which did not break any of my existing
tests , BTW) table-driven property checks.
The issue I am hitting may not be directly related to ScalaTest, but
after investigating the issue, I came to the conclusion that I may be
missing the big-picture. So I am posting here in case I missed a
ScalaTest-specific design decision.
So, I don't expect to get the magic answer that will fix my problem,
but I would be really happy to hear of anything about scalatest that
might help me continue my investigation.
The problem I am trying to solve :
I have some test code that I'd like to run against several databases
The solution I picked (please feel free to give your opinion on this
if it does not make sense):
Using table-driven property checks and a big forAll {} loop that
will run every test for each database
The code is available from :
https://github.com/iglootools/ddddotron/blob/master/integration-tests/src/test/scala/org/iglootools/ddddotron/tests/RepositorySpec.scala
The problem :
val databases = Table(
("name", "dataSource", "txManager"),
("HSQLDB", getBean[DataSource]("hsqldbDataSource"),
getBean[PlatformTransactionManager]("hsqldbTxManager")),
("PostgreSQL", getBean[DataSource]("postgresDataSource"),
getBean[PlatformTransactionManager]("postgresTxManager"))
)
If I ONLY add one of these databases (HSQLDB or PostgreSQL line), and
run all the tests, everything is fine. The code is working fine for
both db (separately)
The cleanup code gets executed before each test, and la vie est belle.
override def beforeEach() {
new SimpleJdbcTemplate(currentDataSource.get).update("""DELETE
FROM event""")
currentEventStore.get.deleteAllSnapshots
}
Now, if I run the tests using the 2 databases, I run into a very weird error :
I end up getting tons of DuplicateKeyException that reflect the fact
that my database is not cleaned-up between each test. Here is
additional information :
- The code does not even get to the second database before crashing.
The simple fact of adding the PostgreSQL line makes the HSQL tests
fail. (whereas they work fine with only one db in the Tables())
- The cleanup code is clearly executed between each test (I added some
tracing to check), but does not seem to have any effect when I add the
additional line
- I still need to further investigate transaction demarcation, but
from what I saw, no matter whether I create transactions or not, the
end-result is the same.
Regards,
Sami
--
You received this message because you are subscribed to the Google
Groups "scalatest-users" group.
To post to this group, send email to scalate...@googlegroups.com
To unsubscribe from this group, send email to
scalatest-use...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/scalatest-users?hl=en
ScalaTest itself, and documentation, is available here:
http://www.artima.com/scalatest
thanks for your answer !
From what I could see with the logging, it looks like beforeEach and
afterEach are executed once for each it() {}
( I am nesting forAll(), describe() and it(), is that OK ?)
I only have one gigantic forAll, and I expect all the tests to be
executed for each database. And in fact, it seems to be the case
sami
Hi Bill,
thanks for your answer !
From what I could see with the logging, it looks like beforeEach and
afterEach are executed once for each it() {}
( I am nesting forAll(), describe() and it(), is that OK ?)
I only have one gigantic forAll, and I expect all the tests to be
executed for each database. And in fact, it seems to be the case
So, I seem to use ScalaTest correctly. The origin of my problem is
probably in my use of JDBC/Spring then !
Thank you !
Sami
My problem was clearly lying in JDBC/Spring. I am still unsure of why
exactly, but now that I use a different application context for each
database, along with a different Spec for each database (that inherits
from the main RepositorySpec), everything is alright.
Thanks again for helping me drill down the issue.
Sami