for testing
What is Groovy?
Java is Groovy... public   class  MethodFakingFunctionMapperTest { private  MethodFakingFunctionMapper  mapper ;   @Before...
(Yes, Groovy is a programming language for the JVM, based on Java)
... but Groovy >> Java //   Bean   creation: def  testBean =  n ew  Customer( surName:  "Newt" , age:  42 ) //  ...
Why Groovy? <ul><li>Conscise syntax </li><ul><li>literals: [],[:],//,  &quot;&quot;&quot;
can be dynamic </li></ul><li># utility methods </li><ul><li>on Object, File, collections, Date, ...
with closures </li></ul><li>GSQL, [object/XML] builder, Gpath, ... </li></ul><ul><li>Productivity
Upcoming SlideShare
Loading in...5
×

Why to write unit tests in Groovy (lightning talk), Q4/2011

502

Published on

Why to use Groovy for unit testing instead of Java and how it increases productivity - its syntax being ~ 100% Java + ~ 1000% more, optional usage of static/dynamic typing, closures, hundreds of utility methods added to the standard JDK classes... .

See http://theholyjava.wordpress.com/2011/10/18/only-a-masochist-would-write-unit-tests-in-java-be-smarter-use-groovy-or-jruby-or-st-else-similar/ for more

Published in: Education, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
502
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
3
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Why to write unit tests in Groovy (lightning talk), Q4/2011

  1. 1. for testing
  2. 2. What is Groovy?
  3. 3. Java is Groovy... public class MethodFakingFunctionMapperTest { private MethodFakingFunctionMapper mapper ; @Before public void setUp() throws Exception { mapper = new MethodFakingFunctionMapper(); } @Test public void should_return_fakeMethod0_for_no_args_call() { mapper .setCurrentExpression( &quot;#{ns:myFun0()}&quot; ); Method actualMethod = mapper .resolveFunction( &quot;ns&quot; , &quot;myFun0&quot; ); assertSame ( FAKE_METHODS [0], actualMethod); }
  4. 4. (Yes, Groovy is a programming language for the JVM, based on Java)
  5. 5. ... but Groovy >> Java // Bean creation: def testBean = n ew Customer( surName: &quot;Newt&quot; , age: 42 ) // Shortcut methods on File etc.: assert test. method () == new File( &quot;expected.txt&quot; ). getText () // Closure-based filter/find/transform on collections: assert customerFinder. findAll (). collect {it.surName}. sort () == [ &quot;Lizard&quot; , &quot;Newt&quot; ] // Literals for maps and lists, comparison for equality via == : assert getCapitalsMap() == [ &quot;UK&quot; : &quot;London&quot; , &quot;CR&quot; : &quot;Prague&quot; ] // Literals for RegExps and utility methods on Matcher : assert ( &quot;dog1-dog2&quot; =~ /dogd/). getAt ([ 0 , 1 ]) == [ &quot;dog1&quot; , &quot;dog2&quot; ]
  6. 6. Why Groovy? <ul><li>Conscise syntax </li><ul><li>literals: [],[:],//, &quot;&quot;&quot;
  7. 7. can be dynamic </li></ul><li># utility methods </li><ul><li>on Object, File, collections, Date, ...
  8. 8. with closures </li></ul><li>GSQL, [object/XML] builder, Gpath, ... </li></ul><ul><li>Productivity
  9. 9. Productivity
  10. 10. Productivity
  11. 11. Productivity
  12. 12. Productivity
  13. 13. Productivity
  14. 14. Productivity
  15. 15. Productivity </li></ul>
  16. 16. We can even use Spock! @ S peck class DataDriven { def &quot;maximum of two numbers&quot; () { expect: Math.max(a, b) == c where: a << [ 7 , 4 , 9 ] b << [ 3 , 5 , 9 ] c << [ 7 , 5 , 9 ] } }
  17. 17. Q & A
  1. ¿Le ha llamado la atención una diapositiva en particular?

    Recortar diapositivas es una manera útil de recopilar información importante para consultarla más tarde.

×