Thursday, January 28, 2010

Unit Tests vs Integration Tests

Let's make it quick and clear :

If a test is not executed on a regular basis, through the build process or continuous integration it is therefore not maintained and becomes a useless test. Maven users would recognize the over-used -DskipTests=true. You can delete it right away, because chances are that within no time it will fail.

Why would you not want to execute the test all the time ? Simply because what was thought to be a unit test is clearly not.

Then how to determine if a test is a Unit Test or an Integration Test ?

  • If a test needs data in the Database , it is an integration test
  • If a test needs a Spring configuration, it is an integration test
  • If a test needs a server to be up (Jetty or application server) it is an integration test
  • If a test is slow it is probably not a unit test.
  • ...
well you get the idea.

A unit test is testing one and only one class.

It does not mean integration test are bad, but they need to be executed in a different cycle from unit test: for example once the build is deployed on a server, etc...

Wednesday, August 26, 2009

Reporting Database

Some thoughts about Domain driven Design, SOA and Reporting database.
From Martin Fowler:
And finally a really interesting one about the trade off between stale data and performance: Eventually Consistent.

Finally let the master talk (Martin Fowler on Domain driven Design Community site):
I'm a growing fan of a separate reporting database. This can reduce the load of complex queries on the operational database, provide a denormalized schema that makes it easier to write queries, and acts as an encapsulation of the operational schema. The downside is that it will lag the operational database to some degree, but often people are quite happy with yesterday's data rather than todays and messaging systems can be used to keep in sync within minutes if you need to.
It says it all !

Wednesday, December 12, 2007

Layout in CSS

Doing my own design using div and float was really painfull - not even talking about the table time. You often need header, menu or tabs, content, footer,etc... and also have to take into consideration specific browser interpretation (box model and so on).

Discovering in the Yahoo! UI library a Grid CSS component, I just decided to give it a try.
Great documentation, quite simple use, in half an hour I have done a simple layout (header, left menu, main content divided into 3 different blocks, right content, and footer ). Not to mention that it is same rendering for different browsers. Everything I needed!

There are three main components:
  • the document : defines the width of the layout
  • templates: ready to use layouts
  • grids: to make more complicated and structured components.
Combining all three components should meet the requirements of most web pages layout.

What is just missing is to have a really simple way to add custom grids (like 40% + 20% + 30%)

If you want to play with it just test the builder.

Wednesday, November 28, 2007

Generating a thumbnail image of a PDF document

Like it exists for HTML pages, I wanted to created thumbnail (preview) image of a pdf document, same as I can get on a Wind*ws Explorer for example.
On the web, given the time it takes to open a PDF document in the Reader, better know before what it looks like, so I don't have to download wrong one.

So I used the PDF Box library. It can convert easily a PDF document to an image.

First need to load the document, get the first page of the document, and convert it to an image:

// Converting first Page to an image
url = new URL(documentPath);
document = PDDocument.load(url);
PDDocumentCatalog catalog = document.getDocumentCatalog();
List allPages = catalog.getAllPages();
if (null == allPages || (allPages.size() == 0)) {
throw new Exception("The document is Empty");
}
PDPage page = (PDPage) allPages.get(0);
BufferedImage image = page.convertToImage();
Then just write the image.

All this can be done calling directly the PDFToImage Main class passing the right arguments (Start page and end page =1).

I tried to reduce the size of the image on a second step (to make it small like a thumbnail) using the code from here, but it often gets to a really bad quality. On web page , better simply size the image.

Also, the underlying code is "beta quality". So shouldn't expect too much from it. ( I tried random PDF from the net, and some of them didn't work. Basically if it standard text it should work.)