A couple of month ago I had an idea for a small web app. But what does it take to do it ? Do you start with the back end or the front end (read server or client side) ? Typically I would start at the back end, get the domain right and then see how I can fit the UI in. If a programmer starts this way you end with the typical ‘the programmer did the GUI’ scenario. That’s not really what I wanted. Don’t think too much about the domain, just see what the needs of the end user are and get the UI done (right).
So I heard about these strange distributed version control systems like over a year ago. I used it in my own little projects and everything went smoothly and I really liked it. The idea also caught on at work and my team started a using Git in a fresh project last summer. We did not had so much problems since you can use Git very much like a central vcs like Subversion if you want to.
Still, for all other code, we used Subversion.
We believe in agile and feature branches, so that’s what we do a lot. Every story has its own branch. If one story touches multiple code bases, that means multiple merge down/copy up’s.
At some point, in preparation for a sprint review, we found that code had disappeared from the trunk. Everything seems to work perfectly, just this feature was missing. Usually you would think if code was deleted, there would be at least one test failing and telling you that something is missing. But no, typing one wrong version number during merge down/copy up cut out the story very cleanly. Once we found the problem we could merged it back in from the not yet deleted feature branch. Overall we managed to work with Subversion but it was a growing pain since we knew there was something better.
There are several advantages of distributed version control system which you all might have heard of already so I won’t go in to detail of this (of course there is also one major disadvantage: complexity). The main advantages for me are:
Developing software ain’t easy.
How do you know how you are doing ?
You could start collecting metrics about your code. These can give you some indication how maintainable and reliable it is.
The metric which come to mind to the most people is code coverage. Some people say it must be near 100%, other say 80% is a good number. At the end it can’t tell you if you are doing great or good. The only thing you might read from it is that a low number indicates a potential problem.
Whenever you create an object you have to find a meaningful name.
While renaming later in modern IDE’s is no problem at all you should not pick the first name which comes to your mind.
Imagine you have an external fraud detection web service and it will return a ‘hit’ or ‘miss’. How do you name this object? HitOrMiss maybe (since this is the representation you get from the webservice) ? It might describe the problem at hand. If you go with this name it will dripple down through all layers. The domain model, the dto’s, services and more will now reference to this object (and create their own derivates for it). Your colleagues which code up other parts of the system will refer to it and create their own variants of the name (like structure for web pages). The wrong name is now all over your code.
So much for refactoring in your IDE. You will never catch all the places automatically where the wrong name was used.
While it seemed lost time discussing the ‘right’ name for 5 minutes in the beginning it saves you much more time afterwards. Of course you might get also confused a couple of weeks later remembering what this thing really does and what it is used for.
Make sure you take time in naming your objects. A wrong decision can do some harm to your code. The later it turns out that the name was not correct the much more expensive it becomes to correct this mistake. If you are not really sure how to name it, talk to your colleagues and discuss the name. A second opinion can not hurt.
Maybe FraudDetectionResult would have been a better choice.
One year ago I started to blog again. Time for a little recap.
Why did I do it ?
I use this blog to write down my own thoughts about software and development. This is for my own reference but also it is a little way to give something back to the world wide community in return for all the useful stuff I do read on the net.
Stats for the last 12 months
I love number so here they are:
About 15.000 unique visitors About 20.000 pageviews
20.64 % Direct Traffic 36.34 % Referring Sites 42.44 % Search Engines
Highest page views on one day: the Selenium 2 post, 620 pageviews (ok, this was big link of the day at dzone.com).
I had visitors from 120 countries.
3362 visitors from United States 2090 visitors from Germany 776 visitors from United Kingdom
I have 142 RSS subscribed readers.
All in all, not too shaby ;-).
Thanks to everybody for reading my thoughts. Thanks for the comments and hints.
I’m looking forward to the next year. It is going to be a great one.
In Response to Matt Raible’s question about my preferred development stack.
In my own development project I switched to Git some time ago. I was using svn and before that cvs for a couple of years. Git just makes it easy to try out small ideas very quickly without reverting the code. We will introduce Git at work pretty soon (I hope).
The Atlassian cloud
I was using Confluence as a Wiki in my open source project and my current employer Hypoport uses it as well. Bug tracking is pretty much a task of Jira. Those two integrate very nicely. You can have ping backs in your Jira Ticket from Confluence, so you see all related files. I would love to use FishEye but I’m not sure how to justify the costs and what the added value is in our case.
I’m pretty much sold to Jetbrains IntelliJ Idea. I’m using it for 5 years now. With it comes Teamcity. It’s a very nice continuous integration tool where the biggest plus (among other things) is the delayed (and pre tested) checkin. No more late night checkins which break the master. We just rolled out the latest version which has a much nicer Git integration (so we can make the switch).
So it comes down to:
- Source control: Git
- Wiki: Atlassian Confluence
- Continuous Integration: Jetbrains Teamcity
- Bugtracker: Atlassian Jira
We are about to use Sonar for code analysis and development over time, but this is just in the beginning.
What’s yours ?
The drawback coding up your tests with the Selenium IDE is: HTML.
You will end up with some test suites including many test scenarios. It will be one big ball of
1 2 3 4 5 6 7 8 9 10
A much nicer approach for me would be something like this:
1 2 3 4 5 6 7
This would log in a user, creates an account and assigns a person to it. Everybody could read and understand it. Furthermore you can easily reuse components and logic. I would imagine that creating a DSL, matchers and finders is everything one would need to have a very nice test scenario.
All that is already possible with Selenium 1 and the language bindings (more or less).
Just with the release of the first alpha of Selenium 2 mid december 2009 it became just a little bit easier.
So given the above example the login method would look something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13
You can take this to any level. It took me just a few hours to model the above use case with componentized input elements.
With a bit more abstraction addPerson looks something like the following code. Whatever is needed to add a person to an account will be replayed. This is what Selenium IDE would normally do.
1 2 3 4 5 6 7 8 9
And now for the best part. You don’t really need a real web browser. Selenium 2 supports 4 WebDriver:
- Internet Explorer (on Windows)
It is very useful to have the Selenium RC take screen shots during it’s run. Selenium 2 can’t do this right now (and with HtmlUnit never can). But by simply integrating some logging in the components and elements and you know right away where things went wrong. Developing with the Selenium IDE might seem like a must, but during the work on my prototype all I needed was Firebug and a XPath Searcher. I did not miss it at all. To do integration tests you could test all components independently and one at a time. Once these work, chain them together and let them run as unit tests. Did I mention HtmlUnit is fast ?
I barely dug into the webdriver code, I played around with it for a couple of hours and I’m sure there more is stuff (and bugs) to find. Given that Selenium 2 is in alpha 1 stage right now I expect very nice things coming out of it. It certainly looks like the way to go.
Another strong contender is Canoo WebTest. I will have a look at this one in another post.
Update Ajax and HtmlUnit 1/5/2010
It does not seem to work. You need a real browser to get dynamically content re-rendered through Ajax.
A method waiting for an id to be rendered (or timeout after x seconds) could look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
This will either find the element specified or throw an assertion (updated example from the selenium 2 page).
We are agile. We do Scrum. We do daily Stand-ups.
A couple of weeks ago we changed our daily stand-up meeting. Our Scrum master came up with the idea to not go around the whole team and everybody talks about what he has done, what he will do and what the impediments are but to make it story based.
Usually after a break down everybody was working on one story, saw the task cards and made sure he did the things he was supposed to do. But this is not enough. You need to have an overview of the whole story (and the sprint). Only with that knowledge you can make sure you will meet the commitment.
So what we started to do is a stand-up meeting based on stories. Every story has a story owner. This is either the person who first started on this story or somebody who is expert in the field worked on. Every morning he is giving a review of how ‘his’ story is progressing, where the problems are and how he could need help. Depending on the priority he gets everything he needs. After presenting the status to the whole team every team member involved gives a smiley on how he feels about the story and the sprint. This way everybody knows what the situation is and how the sprint is progressing.
We found this very effective and it gives every team member a much better feeling about our commitment.
You should try it too.
You are doing scrum, your story is big, you really don’t know much about it and the feature does not get implemented in time.
Sounds familiar ?
I had this a couple of times.
What turned out to be a real problem is that, tech nerds as we are, we spent most of the time coding up a nice solution (and we were almost always convinced that this was the minimum we should have done). What we underestimated was the time we would need to integrate it with the rest of the system. When we broke new ground integrating new technologies it turned out is is very easy to miss that point.
In theory ‘just’ code against a defined interface and you are all set up. In practice you will find the interface not working as intended or web services returning everything wrapped in CDATA. This is the point where you start to panic. This integration was supposed to be easy. Everything else is already working and only a couple of hours where allocated to integrate the new functionality (and sprint review is tomorrow). So it is crunch time, again.
What did we learn ?
If possible (and this is not always the case) start implementing one small feature from top to bottom all the way through your application, e.g. selling green cars through you web site. If this works you can go on and sell blue and red cars. It also helps to organize teams along user stories. This way everybody is responsible for the story.
If you have teams organized along responsibilities like database or GUI, the communication between the team members will suffer (since they usually sit in different rooms). Everybody tries to code up against the defined interface and the integration usually happens pretty late in the sprint. Each team claims that his stuff works against the agreed contract (but still some things do not function as they should). Just hours before the integration should be finished, it turns out the specification was not correct and other things are needed. Back to the drawing board. Overtime. Feature not implemented.
After you got the integration running make sure an automated test is covering it. These need to be expanded over time and you make sure from the beginning that it will always work. It would be very nice to have the integration test running before writing any actual code (read: test driven development) but this never went to well for me since the two sides are very fuzzy in the beginning.
My hope is that next time we come to a situation like this I remember a couple of things I wrote down here :-).
If you want your Business Analyst to provide some acceptance tests for your implementation it would be best to make sure you get it in some form your tests can read. That way you can make sure your code does really do that what the customers wants.
Two tools to achieve that are Concordion and Cucumber (and cuke4duke). Both taking the approach of Fit a step further. You can find very good documentation for the tools on their web pages or as examples along with the code.
Concordion let’s you write the specifications in html. You can instrument them with some Concordion code. Since the instrumentation code is in html, it is hidden when you render it.
1 2 3 4 5 6 7 8 9 10 11 12
Concordion can instrument free text as well as tables to have some sort of data provider for tests. It integrates directly with JUnit (no TestNG support yet).
The idea is that your specifications is stable. This will not change as much as maybe your code to fulfill the requirements of the customer. Your fixture bridges these two together.
1 2 3 4 5 6 7 8 9 10 11 12
Your java code provides the methods which are called from the specification. At that point you are most likely to use a DSL to build up your business logic. Concordion will assert the expected values.
After you run the unit test you will get a nice looking html page.
Passed tests will be green, failed red, pretty easy.
- Instrumention of free text
- The final report is nice looking
- JUnit support
- Easy setup
- Pure Java
- The business analyst needs to know a little bit of html
- Usually the programmer needs to change the specification to instrument it
- You program parts in html, refactoring support is missing
- No TestNG support
Cucumber is a ruby based behaviour driven development tool. Since you can run Ruby code inside the JVM with the help of JRuby it is possible to use it for your Java code. The usually way so far is that you use maven or ant to startup JRuby and the Cucumber ruby code.
In Cucumber you write your specification (or feature) in plain english (or russian, german,lolcode or 36 or so more supported languages). No instrumentation is necessary but your customer has to stick to a certain layout (or better: structure). It follows the well known given-when-then pattern.
Feature: Demo Scenario: A Car with 4 wheels Given I have a car When I add 4 wheels Then I should be able to drive the car
You can write your step definitions (like the fixture in Concordion) with the help of annotations.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
The regular expressions defined in the annotations must match the feature definitions.
You can define information in a table like structure as well to provide more data in an easy way. The given when then structure can be used to have multiple when’s or then’s. So it is very flexible that way.
- Feature can be described in plain language
- No extra programmer work on he feature required
- Instrumentation is directly on the Java code via annotations
- More complex due to the Ruby/JRuby/Java chain
- Business analyst needs to stick to predefined format
- The only way (without extra work to write a runner) to run it seems to be within ant or maven, for rapid turn around and TDD I would like to have JUnit/TestNG support of some kind
It is easy to get started with both tools. I spent about a couple of hours with each of them and was able to get simple and a bit more complex examples running. They get you going with BDD and acceptance based testing.
I like parts of both concepts. I want to be able to write a feature like in Cucumber. The instrumentation should be directly on my code and not in the part of the customer. The easy setup and integration of Concordion with JUnit (need TestNG here) and the output of it is very nice. So where is the tool which has these features ;-).
So which tools will I use?
I have yet to see the use case where the business analyst writes the (and updates) the acceptance tests. I don’t mind add some extra code to the specification and I know html. I might get started with Concordion for now.
You might also check my post about Behavior driven development with EasyB (and vs. TestNG).
Do you use any of these tools? Or a different one? What’s your expierence?
The next-gen cuke4duke was released: Cucumber-jvm. Check out my post on that one.