So with pleasure I am now discovering really nice points of using Groovy - as language that powers the tests and complements the Java main sources. It turns out that even with no frameworks mentioned above, you can benefit just from using Groovy in your test. Here are the reasons:
- You already know almost all of syntax. Old good Java code will probably just work. It is not like JavaScript, which is similar to Java just in name. Rest things you need you can find in documentation - which is quite good and answers most of my questions.
- Forget semicolons, alias imported objects, use list and map literals, multiline strings, use def. Almost like Scala.
- No more @VisibleForTesting. Groovy allows you to break object members visibility. Maybe it is not best idea to look into internal state of objects, but now you can. At least tested methods do not need to be kept in package visibility.
- Power assert. This looks just like Java assert. But output on your console when there is a failure... I just love this feature. Just take a look:
Assertion failed: assert apiResponse.code() >= 200 && apiResponse.code() < 300 | | | | | | | | 404 true | | 404 false | | retrofit2.Response@42d0a255 | false retrofit2.Response@42d0a255
- BigDecimal everywhere. 42.0 is not a float any longer. If your code has something in common with money you can feel relief.
- @TypeChecked. Why not just use compiler? With Groovy you can! It is so nice when machine corrects your errors.
No comments:
Post a Comment