A Couple of Eclipse Tidbits for Testing
Join the DZone community and get the full member experience.
Join For FreeI finally mapped Rerun JUnit Test using the keymapping stuff in eclipse. I know there was already a way to get to it using those key combinations where it‘s like 3 and then a letter afterwards. Too much work. I chose command-Shift-J (since I have become seriously kneejerk about command-Shift-F), it‘s kind of same bit on the other hand. Makes a huge difference, however, when you switch between tests you have to remember that it is not going to run the test you are in.
Made a template for adding the Spring runner stuff to the top of tests.
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/${contextFile}.xml" })
@TransactionConfiguration(defaultRollback = true)
${cursor}
Was thrilled to see the third one can be added so I don‘t have to think about rollback. However, you do have to mark the tests themselves as @Transactional and I got bitten by that again. The rule there is pretty simple: if you have a simple test, that calls one method on the Repository, it will likely work w/out the annotation on the test. Soon as you try and say, create 2 things, then do a find to make sure it‘s seeing them, you will get transient errors, even though the cascades are there. Once I added the annotation, I got an error about CGLIB not being present. Added the dependency to the pom and the problem went away.
Here‘s a template for doing a suite. Of course, it won‘t add the classes for you, but the wizard in the plugin does not support 4.x syntax (per prior post):
@RunWith(Suite.class)
@Suite.SuiteClasses( { ${classNames} })
Another stupid thing happened today where I
was writing a test that submitted a couple events then did a query for
all events since. I made the date doing the usual Date begin = new
Date(), then created the 2 events, and have a since clause on the query
and I passed it the begin. The thing was failing. Added
Thread.sleep(10) and it passed.. ? So apparently, it was looking like
the same date, even though, it was a TIMESTAMP (TemporalType),
and I used the 3 argument setParameter call to stipulate so. Figured
the 10ms delay was preferable to adding a bunch of ugly JDK-based date math. (Thrilled to find the other day that Hibernate now has support for persisting Joda types.)
From http://www.jroller.com/robwilliams
Opinions expressed by DZone contributors are their own.
Trending
-
How To Design Reliable IIoT Architecture
-
Tomorrow’s Cloud Today: Unpacking the Future of Cloud Computing
-
Auto-Scaling Kinesis Data Streams Applications on Kubernetes
-
Merge GraphQL Schemas Using Apollo Server and Koa
Comments