• 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

Unit testing

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unit testing has been a real challenge ever especially when someone needs to work a lot around legacy code, mocking, not-to-hit-database etc. Many times I had to reinvent the wheel to write test programs while working in those areas. Is there any new idea introduced in Java 8 ?

Thanks.
 
author & internet detective
Posts: 41083
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
Have you read Working Effectively with Legacy Code? The book is a decade old, but still up to date. That's something nice about legacy code - it isn't cutting edge.
 
Marshal
Posts: 5326
324
IntelliJ IDE Python Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
+1 for Jeanne's book recommendation.

Since reading it I actually quite enjoy working with Legacy code now. The prospect of finding a tangled mess of code used to fill me with dread, with the first though in my head being "I'm not touching THAT!". But now I get to have a good laugh at the ridiculousness of it and relish in the challenge of taking it on. Then bask in the glory once it's all been nice and safely refactored.

Turns out this is a large part of what it means to be a half decent Software Engineer.
 
Author
Posts: 26
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Baskar,

Lambdas can enable you to do testing in a more declarative BDD approach. See this link for an example: http://www.blog.project13.pl/index.php/coding/1830/proof-of-concept-lambdaspec-how-testing-will-look-with-java8/

 
Greenhorn
Posts: 2
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some cases for unit testing with Java 8:

1. One can use lambda expressions in test code to implement lightweight stubs. if the collaborator to be stubbed is a functional interface. I found a neat description of this approach in "Java 8 Lambdas" book (http://www.amazon.com/Java-Lambdas-Pragmatic-Functional-Programming/dp/1449370772/ref=sr_1_1?s=books&ie=UTF8&qid=1404769897)

2. Lambda Expressions can help in testing exceptions in JUnit and therefore can easily replace libraries like catch-exception or even plain JUnit @Rule.

Having simple functional interface like this:



We can achieve a syntax like below:



Please have a look at blog post that describes this approach in more detail: http://blog.codeleak.pl/2014/07/junit-testing-exception-with-java-8-and-lambda-expressions.html
 
Marshal
Posts: 75669
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Is that your own blog?
 
Rafał Borowiec
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Indeed. But the book I did not write.
 
You firghten me terribly. I would like to go home now. Here, take this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic