Mittwoch, 23. November 2011

Test Doubles and Mocking Patterns

Yesterday I refactored a unit test with over 2000 lines of code, now the test has around 900 lines of code. One pattern I found in the test was that for every kind of test double a mock object was used.

I prefer the following test design rule for mock objects and test doubles. Object which contains logic e.g. of type service, factory or repository should be mocked instead of DTOs, value objects or entities (plain Java Beans) with getters and setters e.g. configuration objects this kind of object should never be mocked.

Here small example, a test with to much mocking, please don't write such kind of tests:

This simple unit test above has to much mocking logic and should be refactored to this test:

If you like you could use the builder pattern for the simple objects like sale to get the test a little bit nicer (see the links for eclipse tooling). A smell is when you need to mock classes, in most cases then you should use another test double pattern for this kind of objects, or something with the design of the SUT is wrong.

What I like to say is you should not always use our preferred mocking framework to create a mock object as test double for everything. There are situations where mock object I believe are a test design anti pattern / smell. Think about stubs and dummy object before creating a mock object and read the great xUnit test pattern book “xUnit Test Patterns” from Gerard Meszaros. Then you are on the right way to get an agile tester ;-)


Donnerstag, 17. November 2011

OSGi Users' Forum Germany Community Event 2011

This year the OSGi UFG Event was based in Cologne. The event was great a lot of new input. My favorite topics were PojoSR and OBR (OSGi Bundle Repository). A great podiums discussion on OBR there was a great discussion about commercial bundle repositories "App Store for Bundles".

Richard Nicholson (OSGi Alliance President) could not make it to event, because he has an important meeting in UK . So we shortly changed the Keynote "OSGi Alliance Update" to "OSGi Community Update". In this session I tried to give an overview what happens in the OSGi World/Community in the year 2011. I believe I missed a lot of stuff, but when I prepared the session I become the feeling 2011 was a lot of work in OSGi Community done. I think OSGi was not much in the news but a lot of new open source projects and also a lot of progress in the OSGi specification was done. For example the enterprise specification was finished, the OSGi Core specification 4.3 was released in April, the package admin is now deprecated, we have now a much better API the Wire API. Also in the tooling area much happens in this year. I think BNDTools could become the standard tooling for OSGi. Hope Neil well release the BNDTools Version 1.0.0 this week ;-)

The first session on the UFG was about OSGI in Healthcare applications and smart cards. The talk covers the n-pad product which is used for the German "Gesundheitkarte". Stephan Hoffmann-Emden and Andreas Klotz shows in short live demo how there OSGi based smartcard reader works. They have built a PKI Service for their OSGi platform. Is there a standard for PKI / crypto handling in OSGi?

In the next session Andreas Kraft cover the topic "OSGi in the Residential Market". Andreas gives a good overview which topics will be in the OSGi Residential specification. The talks give also a short introduction in the OSGi Alliance Processes e.g. what is an RFP and so on.

After a small coffee break Holger Hoffstätte gives a really nice overview on OBR. His statement the important thing about OBR is the model. I think OBR will fix a lot of problems in OSGi tooling and deployment. I think it will also play a rule in the SEITENBAU OSGi projects. OBR solves a lot of problems we have at SEITENBAU and we now have solved by custom solutions. So we need it right now.

In the podiums discussion "OSGi Bundle Repository versus Apache Maven Repository" we have lot of good discussion. Okay the title was not perfect ;-).

First session in the second track after launch was PojoSR my favorite session. Karl Pauls explains why we need PojoSR and how to migrate Projects to OSGi by using PojoSR. He also covers very well the problems when migrating existing projects to OSGi. I think Pauls statement is absolute true PojoSR brings µServices to the rest of us.

Ralf Sternberg and Frank Appel shows with a great live demo how to use RAP with OSGi. They also explains how RAP application benefit by using OSGi. I didn’t know the actual RAP Version is based on OSGi services and do not use the eclipse plugin registry. I hope will have a little free time to try and play around with the actual RAP version. In the session Ralf and Frank shows also a RAP based smartphone client.

After the RAP session Stefan Kachel introduce the eclipse project Riena. Riena makes the SWT UI development much easier. There is also an eclipse toolbox provided by the Riena project, which makes the development of Riena based applications much easier. Stefan shows how to use Riena by a running example application.

Kai Hackbarth gives a session about "OSGi for In-Vehicle Systems". He explains how car sellers benefit by using OSGi as basic platform for the products. In the session Kai gives also a nice overview of the alternative platforms like android which are used in vehicle systems. Good news there are already OSGi deployments, Kai gives some examples where OSGi is already deployed.

Last but not least a really cool session on the topic how normal web application could benefit by using OSGi from Jan Ehrhardt. Jan shows the reality, the problems and why in many cases normal web applications not benefit by using OSGi. In the second part of his session he shows in which situations and how web application could benefit by using OSGi. In the last part of his session he shows how OSGi could be used in different Java EE environments e.g. embedded in tomcat, next generation EE applications server or OSGi as standalone application e.g. by using Apache Karaf.

Was again a great Users Forum Germany community event with great sessions thanks to the audience and the speakers. Only the date was not perfect chosen there where parallel in London UK a face to face meeting. Next time we will make it better I believe ;-)

In next couple of day I will make the last slides available I hope via slideshare and I will also linkt the link to the slides from the UFG website.