Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

12. Meta-Programming > Testing Java with Groovy

Testing Java with Groovy

Groovy is the dynamic language syntax for Java. As such, it can interact pretty seamlessly with Java code (including compiled byte code), allowing you much more flexible syntax. Groovy makes it possible for you to do a bunch of stuff on the Java platform that is difficult or impossible using Java.

You can invoke the standard reflection mechanism in Java using the Groovy syntax as shown in this listing, which replicates the test for isFactor shown earlier:

@Test public void is_factor_via_reflection() {
  def m = Classifier.class.getDeclaredMethod("isFactor", int.class)
  m.accessible = true
  assertTrue m.invoke(new Classifier(10), 10)
  assertTrue m.invoke(new Classifier(

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint