Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

How can lambdas be used to test your code?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We have a java-based test framework and use testNG. How can lambdas be used to simplify code testing?
 
Marshal
Posts: 75643
354
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't know myself, but welcome to the Ranch
 
Ranch Hand
Posts: 434
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is one chapter about testing lambda expressions. If I remember it right, it's chapter 7.
 
author & internet detective
Posts: 41073
848
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Teresa,
Welcome to CodeRanch!

I think you are asking about how lambdas can simplify your test code. (rather than how to test lambas).

I think most tests will be too simple to benefit. But tests with more complex assertions can be simplified. For example, I often write a helper assertion method that looks like:



Yes, I could use a comparator, but then I'd be writing it just for this method. With lambas, I could express this whole method in one line.
 
Author
Posts: 31
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Teresa Sparkman wrote:We have a java-based test framework and use testNG. How can lambdas be used to simplify code testing?



Hi Teresa,

I think the biggest benefit isn't their direct usage in test code, although there is a good example elsewhere in this thread of that happening, its actually in making it easier to abstract over different behaviours. Being able to pass in some behaviour as a parameter makes it a lot easier to write code which is testable. In the same way that depending on any abstraction makes it easier to write code that's testable.

regards,

Richard
 
These are the worst of times and these are the best of times. And this is the best tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic