Proof of Concept – LambdaSpec, how testing will look with Java8

Posted by Konrad 'ktoso' Malawski on 26/05/2013 – 22:02;

I recently had an hour or two to spare, so I decided to play around with Java 8 and it’s Lambdas. Coming from Scala and knowing the Spec of lambdas (I’ve been checking it out on each update) I went straight on to implementing anything useful with them.

I decided that Java will eventually get a testing framework using lambdas, in a more BDD way. My favourite example of such framework is ScalaTest (by Bill Venners) which i wholeheartedly love nowadays. So my goal was to implement something similiar, wihin what’s possible with Java currently.

And here’s how a passing / failing and pending test would look like:

So pretty much like you’d expect it from a good testing framework nowadays. Truth be told – reading junit in the terminal is a horrible pain so you have to use your IDE for browsing test failures. (I honestly like my terminal output to be meaningful enough for testing – that way I always have all tests running on one screen, and am writing code on the main screen).

You may ask why this verbosity is a nice thing. That is: “Why not use annotations, like we always have?”. One of the answers is the bellow snippet, which displays how generating test data, and meaningful test names, and the tests themselfes are very easy to track and understand (this is not yet implemented):

Or another style (yet to be improved):

LambdaSpec is for now just a Proof of Concept, but eventually I hope to get it to the point that once J8 is released, we’ll be able to use it instead of JUnit. Some of the nice features I want to bring in would be smart test dependency analysis (so only the tests that may have failed will be run) and a separate runner… Think ~test if you know ScalaTest… :-)

Anyway, if you’re interested in Java 8 and what’s coming up, i encourage you to star the project (it’ll give me the necessary power to push this thing forward ;-)).

Check out the sources at https://github.com/ktoso/lambda-spec

Tags: , , , , ,

This post is under “coding, english, java” and has no respond so far.

Post a reply