What's the best way to test using grails using IDEA?

I'm seriously having a very enjoyable time using Grails. I will describe my experience and I would like to know if there is a better way.

  • The first problem I run into in testing is that Grails doesn't give immediate feedback to the developer when .save () fails inside an integration test. So let's say you have a domain class with 12 fields, and one of them violates the constraint and you don't know it when you instantiate it ... it just doesn't save. Naturally, the test code will fail after doing this.

This is very troublesome because the thing being tested is probably beautiful ... and the real risk and pain is the setup code of the test itself.

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

  1. Integration tests are slow. I can't figure out how 1 integration test that saves 1 object takes 15-20 seconds to run. With some careful planning for testing, I was able to get 1000 tests talking to a real database and dbunit dumped after each test, which happens at about the same time! This is stupid.

  2. It is difficult to execute all unit tests and not integration tests in IDEA.

  3. Integration tests are a huge pain. The idea actually shows a GREEN BAR when integration tests fail. The result given by grails indicates something didn't work, but it doesn't say what it did. He says to look in the test reports ... which forces the developer to fire up their filesystem to find the stupid html file. Such a pain.

Then as soon as you get the html file and click on the failed test, it will tell you the line number. Since these reports are not in the IDE, you cannot just click on the stack trace to get to that line of code ... you have to go back and find it yourself. ARGGH! @! @!

Maybe people put up with it, but I refuse. Testing doesn't have to be that painful. It has to be quick and painless, or people won't.

Please, help. What's the solution? Rails instead of Grails? Something else? I love the Grails framework, but they never demonstrate testing them for some reason. They have amazing structure, but testing is painful.

After using Scala for the last 1.5 months and a completely spoiled ScalaTest ... I can't go back to this.

+2


a source to share


1 answer


You can set this property in your config file:

grails.gorm.failOnError=true

      

This will make it the system default for saving (which you can override with .save (failOnError: false) if you like).

If you only want this behavior in your test, you can put it in this inline structure in Config.groovy. I really like this as a project behavior.

I'm sure this is a way that you can enable / disable failOnError within a specific scope, but I haven't researched how to do it yet (maybe a good blog post, I'll update this if I write one).



I'm not sure what you configured incorrectly in IDEA, but it shows me a red bar when my tests fail and I can click lines on the stack and get right to problems. The latest version of intellij even breaks most of the metaclass cracks, which is not interesting when trying to troubleshoot issues.

If you haven't done so already, to generate your project, I'll try to erase the existing .ipr / .iml / .iws / .idea files and run this command to have grails update your config:

grails integrate-with --intellij

      

Then run the generated .ipr file.

+2


a source







All Articles