views:

96

answers:

1

I am seriously having a very non-pleasant time testing using Grails. I will describe my experience, and I'd like to know if there's a better way.

  1. The first problem I have with testing is that Grails doesn't give immediate feedback to the developer when .save() fails inside of an integration test. So let's say you have a domain class with 12 fields, and 1 of them is violating a constraint and you don't know it when you create the instance... it just doesn't save. Naturally, the test code afterward is going to fail.

This is most troublesome because the thingy under test is probably fine... and the real risk and pain is the setup code for the test itself.

So, I've tried to develop the habit of using .save(failOnError: true) to avoid this problem, but that's not something that can be easily enforced by everyone working on the project... and it's kind of bloaty. It'd be nice to turn this on for code that is running as part of a unit test automatically.

  1. Integration Tests run slow. I cannot understand how 1 integration test that saves 1 object takes 15-20 seconds to run. With some careful test planning, I've been able to get 1000 tests talking to an actual database and doing dbunit dumps after every test to happen in about the same time! This is dumb.

  2. It is hard to run all the unit tests and not integration tests in IDEA.

  3. Integration tests are a massive pain. Idea actually shows a GREEN BAR when integration tests fail. The output given by grails indicates that something failed, but it doesn't say what it was. It says to look in the test reports... which forces the developer to launch up their file system to hunt the stupid html file down. What a pain.

Then once you got the html file and click to the failing test, it'll tell you a line number. Since these reports are not in the IDE, you can't just click the stack trace to go to that line of code... you gotta go back and find it yourself. ARGGH!@!@!

Maybe people put up with this, but I refuse. Testing should not be this painful. It should be fast and painless, or people won't do it.

Please help. What is the solution? Rails instead of Grails? Something else entirely? I love the Grails framework, but they never demo their testing for a reason. They have a snazzy framework, but the testing is painful.

After having used Scala for the last 1.5 months, and being totally spoiled by ScalaTest... I can't go back to this.

+1  A: 

You can set this property in your config file:

grails.gorm.failOnError=true

That will make it a system wide default for save (which you can override with .save(failOnError: false) if you want).

If you only want this behavior in the test, you can put it in that environment specific stanza in Config.groovy. I actually like this as a project wide behavior.

I'm sure theres a way that you could turn failOnError on/off within a defined scope, but I haven't investigated how to do it yet (might be a good blog post, I'll update this if I write one).

I'm not sure what you've got misconfigured in IDEA, but it shows me a red bar when my tests fail and I can click on the lines in the stacktrace and get right to the issues. The latest version of intellij even collapses down the majority of metaclass cruft that isn't interesting when trying to fix issues.

If you haven't done this already to generate your project, I'd try wiping away your existing .ipr/.iml/.iws/.idea files and running this command to have grails regenerate your configuration:

grails integrate-with --intellij

Then run the .ipr file that gets generated.

Ted Naleid
Actually, there was a bug in 9.0.2 with grails that was causing this green bar problem. Once I upgraded to 9.0.3, it worked. Figures ;)
egervari