Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

A Couple of Eclipse Tidbits for Testing

DZone's Guide to

A Couple of Eclipse Tidbits for Testing

· Java Zone
Free Resource

Bitbucket is for the code that takes us to Mars, decodes the human genome, or drives your next car. What will your code do? Get started with Bitbucket today, it's free.

I 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


 

Bitbucket is the Git solution for professional teams who code with a purpose, not just as a hobby. Get started today, it's free.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}