Posts Tagged ‘unit testing’

Online service development in java – a beginner’s guide

November 4, 2012 1 comment

In the coming series of posts, I will share my development experience (code included) with creating an online service from scratch.  If you read through all posts, you should reach a point where you are capable of writing code and deploying it to a production like environment which is available online, using some of the latest (and greatest) open source libraries available in java.  You will definitely not be at the end of the journey, but will get a pretty good head start.

I’ve created a sample project, which basically does nothing (well, almost nothing), but it does so in a (semi) secure way, using several top libraries.  Basic service, is a service which lets you register, login, and… do nothing.  But, it does so using:

Spring, Maven, ESAPI (+AppSensor) for input validation, JSP’s (JSTL+Tiles 2), jQuery (+UI), Mongo DB, Logback, Jackson, Mockito (+PowerMock) for unit testing, and it does it in a RESTful way, using complete Data and Presentation separation (all JSP’s get their data through REST requests, meaning you can add easily add mobile support without almost any change to the  interface), and is fully internationalized (currently supports hebrew and english, meaning we have RTL languages covered).  The complete source code for Basic service is available on google code, it is a fully functional (and GPL open source) example of combining all of these technologies , which means that you can concentrate on the next steps rather than spend time building the foundation from scratch.  It took me about 3 months to go through all the baby steps in each of those technologies (after spending some time picking the right ones of course), I hope this series will save you at least some of that time.

Please keep in mind that I do not claim this to be a complete and bullet proof piece of software, there is still much to do in order to make it “production ready”.

Basic service is deployed on Cloudbees, using Continuous Deployment,  you’ll get some insights on how to do that as well.

One final note: the title says “a beginner’s guide”, but should be read with two different interpretations: one is (possibly) you, who is just getting started with creating an online service, and the other is me, sharing my experience with jumping into these deep water a couple of months ago.  If you like what you read, you’re welcome to comment, if you see me making horrible mistakes, constructive criticism is more than welcome.

Let’s move on.  The next post will cover the basics of setting up a functional development environment, one which will allow you to develop and instantly deploy your code to production so it is available to the rest of the world


Writing Unit tests – a beginner’s experience log

November 2, 2012 Leave a comment

I have to admit the embarrassing truth: I’m a Unit Test noob.  While Unit Testing has been around for a while, and my teams had been writing them for quite a while, I’ve never had the chance to write them myself, and never had the time to invest in learning what they’re all about.

Since I’m now the developer in my startup, and living without Unit Testing is impossible when working in a Continuous Deployment style of product development, it’s time to dive in.

I’m a “read all about it” kind of a guy, so naturally I searched the web for stuff to read.  I’ve found a decent book called Junit in Action which was good for understanding what Unit testing means and what JUnit is all about, but that was not enough to start using the frameworks I’ve chosen (see my post here)

So, onward to online resources.  I went into the Mockito webpage, and read the documentation and example page there, which gave me a better idea of the structure.  I also read this post called “Mocks aren’t Stubs” by Martin Fowler, which gave me a better understanding of how writing Unit tests can actually get me to write better code.  Another interesting reads can be found here, and here.  I also tried to create a unit test for one of my classes (not too complex, but proved to be a challenge which forced me to use PowerMock).

In the end, there’s no better way to learn than to try to do it on your own.  I’ve read about 30 different posts from people with different implementation problems, style questions, etc., and I can proudly say I’ve finally created my very first Unit test which actually runs and verifies behavior!

Categories: R&D Tags: , ,