Blog

Spring Conference – Some Notes

I recently attended the SpringSource S2G Forum Series at the London Hilton. There were some good sessions being presented, and sometimes I wish I could clone myself, as more often than not, there’s always more than one really good session running in the same time slot!

My three big take-aways were Tomcat 7, Spring MVC 3.1 update and the Spring Data Project, which I’ll talk about here.

Tomcat 7

So, first up, after the keynote, was a brush over what’s new in Tomcat 7. I must say, there are some rather neat enhancements in v7 that I’ll be looking forward to(but not necessarily using):

  • Support for parallel deployment
    • This is fantastic IMO. This enables you to deploy multiple different versions on the same web application (WAR) concurrently, all being accessed by the same context path. Tomcat will automatically route new sessions to the latest version of the application, while current sessions on older versions will continue their requests to those versions until their session expires. This greatly reduces deployment costs, and having to worry about deployment upgrade schedules/windows. Upgrading using parallel deployments will make upgrading seamless.
  • The ability to configure an active tomcat instance via JMX from just running the server component.
    • I think this is great news for those who want absolute control over how their Tomcat instance is configured. With the capability of being able to configure tomcat in this fashion, opens the doors for tools/utilities to be written to programmatically create instances just how you like them.
  • The new Cross Site Request Forgery(CSRF) protection filter
    • This filter basically generates a nonce value after every request, and stores the value in the user’s session. The nonce has to be added as a request parameter on every request, and Tomcat will verify if the values are the same, to check to see if the request wasn’t from somewhere else.
  • Various default configurations
    • Access Logs on by default
    • LockoutRealm used by default
    • DefaultServlet serves content from the root of the context by default

I was glad to hear that SpringSource tc Server and the Tomcat 7 source were being kept in line , and felt at ease when I was reassured that whatever changes are being made in TC7 are soon finding their way into SpringSource tc Server.

Spring 3.1 MVC Update

I’m noticing more and more of a focus these days on Java based configuration with Spring, and this was highlighted in the Spring MVC session. Rossen Stoyanchev did a good job highlighting this point, and gave some good examples which demonstrated this. I’m still not 100% converted though, and I still feel that there is a place for xml configuration, but if I’m honest, I am beginning to find myself coding my configuration more these days.

There is much better support now for making customisations to any one or more aspects of the mcv namespace. whereas before if you were happy with the default configuration setup, all you previously had to do to setup most of the web bits was to have the following line in your xml config:

<mcv:annotation-config/>

However, if you wanted to setup an xml marshaller for example, then you pretty much had to redefine all the parts that the previous convinience xml fragment did for you. This was very much a pain, and now is easy to accomplish.  All that is required is that you annotate your configuration class with @EnableWebMvc(yes, you have to use the java based configuration route if you want to avert the previous pain) and extend the WebMvcConfigurerAdapter class. The WebMvcConfigurerAdapter class provides you with many callback methods to add to/modify what is configured by default.

Along with easier MVC configuration, there is also now a bit more transparency about what gets configured for you under the hood. If you take a look now at the WebMvcConfiguration class, you can now see what’s being configured for you now by default.

Other areas which were mentioned, but I am yet to explore, are features around pre/post validation hooks, as well as pre/post bind when binding your form object to a controller method invocation.

Spring Data Project

Now this is something quite exciting, and rather new to me. I like the idea Spring has here to build a data-access framework to give developers the capability to have their business object data stored in different data stores. The clever people over a SpringSource have built it in such a way that you can even have different parts of your domain object for example, stored in different data stores, so you might have some info stored in a graph database, some info in a regular RDBMS store, and if you have data that has no relation to anything, but you still need to store it, you can have that stored in a NoSQL data store, and all this, will be transparent to the user. Brilliant! If you have a application that stores data(who doesn’t?!), then I’d strongly suggest that Spring Data be given a once over. I for one think its a move forward in the right direction, empowered to store your data where it needs to be stored best, without having to worry about the vast amount of plumbing involved to get it done!

Maven android plugin and the –core-library build option

I’ve recently been working on building some android based applications now for the past 3 or so months, and its been a fantastic journey so far. However, there have been times where I’ve found I talk to myself quite a bit, and for most part, I find myself muttering “what the heck is that supposed to mean?!”

This was one such occasion. I use maven for building my android project, but I had recently started using Springs RestTemplate, and there were a few libraries that I had to import while attempting to build REST based communications.

One thing that caught me off-guard, was, that when I came to build the project, I was now presented with a number of errors, all with the same sort of warning which read as:

[INFO] [android:dex {execution: default-dex}]
[INFO] C:\Program Files\Java\jdk1.6.0_20\jre\bin\java [-jar, C:\Program Files (x86)\Android\android-sdk-windows\platform-tools\lib\dx.jar, --dex, --output=C:\dev\android-sample\target\classes.dex, C:\dev\android-sample\target\android-classes]
[INFO]
[INFO] trouble processing “javax/xml/bind/annotation/adapters/CollapsedStringAdapter.class”:
[INFO]
[INFO] Ill-advised or mistaken usage of a core class (java.* or javax.*)
[INFO] when not building a core library.
[INFO]
[INFO] This is often due to inadvertently including a core library file
[INFO] in your application’s project, when using an IDE (such as
[INFO] Eclipse). If you are sure you’re not intentionally defining a
[INFO] core class, then this is the most likely explanation of what’s
[INFO] going on.
[INFO]
[INFO] However, you might actually be trying to define a class in a core
[INFO] namespace, the source of which you may have taken, for example,
[INFO] from a non-Android virtual machine project. This will most
[INFO] assuredly not work. At a minimum, it jeopardizes the
[INFO] compatibility of your app with future versions of the platform.
[INFO] It is also often of questionable legality.
[INFO]
[INFO] If you really intend to build a core library — which is only
[INFO] appropriate as part of creating a full virtual machine
[INFO] distribution, as opposed to compiling an application — then use
[INFO] the “–core-library” option to suppress this error message.
[INFO]
[INFO] If you go ahead and use “–core-library” but are in fact
[INFO] building an application, then be forewarned that your application
[INFO] will still fail to build or run, at some point. Please be
[INFO] prepared for angry customers who find, for example, that your
[INFO] application ceases to function once they upgrade their operating
[INFO] system. You will be to blame for this problem.
[INFO]
[INFO] If you are legitimately using some code that happens to be in a
[INFO] core package, then the easiest safe alternative you have is to
[INFO] repackage that code. That is, move the classes in question into
[INFO] your own package namespace. This means that they will never be in
[INFO] conflict with core system classes. JarJar is a tool that may help
[INFO] you in this endeavor. If you find that you cannot do this, then
[INFO] that is an indication that the path you are on will ultimately
[INFO] lead to pain, suffering, grief, and lamentation.
[INFO]
[INFO] 1 error; aborting
[INFO] ————————————————————————
[ERROR] BUILD ERROR
[INFO] ————————————————————————
[INFO]

Now that’s a pretty scary error to have, and on subsequent investigation, it seems like some marshalling libraries I’ve imported have the same namespace as some included java namespaces. Not to worry, I trust that the developers of this marshalling library know what they’re doing, so I just want it to build. But alas, following the instructions to use the –core-library option, the maven-android-plugin still refuses to build, and you just get back the same build error message.

I then found this nice bug report, which detailed pretty much everything I was experiencing – thank you to whoever you might be! So I thought the least I could do was fix the bug, if it was so well logged!

It turns out that the maven-android-plugin had a small bug in it, where the order of the options weren’t quite 100%. The GitHub pull request is here, and it has been accepted, so I assume it will be available in the next release.

I hope this helps anyone else out there experiencing this problem.

Feedback on Specification by Example

Last Friday, four of us attended a seminar in London on specification by example delivered by Gojko Adzic, a thought leader in strategies around software delivery. Specification by example is a set of process patterns that facilitate change in software products to ensure that the right product is delivered efficiently. Gojko delivered the session very interactively and with lots of humour and cringe worthy real life examples. I believe we left feeling we could and should adopt some if not all of the patterns he covered.

This is what I have taken away from the afternoon.

The only way good specifications come about is when business users/customers/product owners work collaboratively with designers, testers and builders to come to a common understanding of what is required. Often, business people and technical people have their own jargon and that can be (and needs to be!)  aligned by working closely together. In working together, it is important that business people focus on their goals and not dictate what should be done or how the system should do it. On the other hand, developers have a tendency to discuss technical details that are of no interest to business people. It’s a learning process to find the common ground where both parties feel they can contribute.

Here is a summary of the patterns that Gojko discussed:

A) Do not start with user requirements! Start with business goals/visions/outcomes. Business goals are important to business users and customers, systems and functionality are not. Gojko threw in two more comments that stuck with me in relation to this. Firstly, working on anything other than your customer’s main pain point or no 1 priority is risky and could be a waste of time. Secondly, if you cannot find a business sponsor willing to take the time to work on a business goal, it’s probably not worth spending time on.

B) From the business goal, derive a scope of what needs to be done to achieve that goal. Scope would typically be expressed in user stories or use cases. Multiple features might be needed to achieve one goal.

C) Illustrate each feature with key examples that are precise and clear to everybody.

Example: say we have to build a feature that gives customers free delivery if they order 10 books or more:

Customer orders 10 books Delivery is free
Customer orders 9 books Delivery is not free

By using plain language examples, anybody can understand what is expected of the system and can more quickly spot issues. What if the customer orders 10 books and a fridge?

These examples facilitate discussions. It is important that these examples illustrate what the system should do, not how it should do it.

Another point Gojko made was not to overdo it. Too many examples will reduce clarity. If examples get too complicated (with too many variables), Gojko suggested introducing a new business concept to hide some of the complexity. That concept can then have its own separate set of examples to illustrate it.

D) Once the key examples are written down they need to be discussed and refined to ensure they are as simple and clear as possible. This results in specifications with examples which are easy to read. These examples can be used as acceptance criteria for delivery.

E) At this point, someone could manually test these examples against the system. If the nature of the system allows it, it is more beneficial in the long run to automate the testing. There are plenty of great tools available in the open source community to achieve this automation. One of our consultants (Nathan) has successfully integrated Concordion with SAP to enable this automation.

F) Automation needs to be done by adhering to the letter of the specification. Changing the specification at this point is often tempting but must be avoided at all cost in order not to test the wrong thing.

Luckily, there are tools out there that are capable of parsing plain human readable text, pass the key pieces of information to a test system and verify the results that come back from the tests by comparing the results with what is writing in the text. That way, they can decide whether a test has passed or failed. It’s this powerful concept that makes test automation possible at a business level as opposed to automating technical (unit) tests that are hard or impossible for business users to understand.

G) At this point, you build up a set of executable specifications that can be validated frequently.

H) The last step is to organize these specifications into a business framework (from a business users/customers point of view, not from a technical point of view!) and at that stage, the specifications become living documentation that is guaranteed to contain a single version of the truth about the system.

The benefits of working this way according to Gojko are predominantly:

  • higher product quality
  • better test/dev alignment
  • implementing changes more efficiently
  • less rework

G3 Global Customer Portrait for SAP’s ERP offerings aimed at SME/SMBs

It’s often assumed that SAP ERP is aimed at large multi-national companies like Siemens, Shell, & Albemarle Corp for instance but it will surprise many that more than 70% of SAP customers around the globe are actually defined as being in the SME market.

SAP has spent literally billions of dollars in recent years on R&D, drawing on the vast experience of working with some of the best run companies in the world to develop and perfect 3 separate products that are aimed squarely at the SMB/SME market: SAP Business One, SAP Business By Design & SAP Business All-In-One.

SAP Business One  is SAP’s entry level solution and is designed to meet the needs of small businesses who need a complete and integrated business suite straight of the out of the box.

SAP Business ByDesign is an integrated solution that is adaptable and has been specifically designed for dynamic midsize companies that need to be responsive to changing circumstances and accommodate the potential for growth.

The SAP Business All-in-One solution has much of the flexibility of the full large enterprise SAP ERP system, but it is based on sound pre-configured best practice processes that reduce implementation time, costs and risk, and therefore increase the return on investment.

In this brief audio-visual presentation, we discuss why we choose SAP’s Business All-in-One product when we decided that the systems we started with could no longer effectively support a young, successful and growing organisation in this space.

1 minute glimpse of SAP ERP for the SME and SMB Market

This is a very quick (one minute) and compelling argument for the use of an ERP system to bolster small to medium sized business (SMB / SME) in the current difficult economic climate.

We discuss the challenges faced by the typical SMB; reducing costs, and maintaining good, innovative customer service, whilst staying agile enough as a business to be able to accommodate growth and change. We see that integrating, rationalising and standardising business processes across the enterprise with the support of a well engineered ERP solution can give that business a much needed competitive advantage at a relatively modest outlay making an attractive value proposition.

SAP have developed in a product range (Business One, Business By Design & Business All-in-One) in recent years that is specifically targeted to support smaller sized enterprises wherever they are in they are in their evolutionary cycle. It is clear that SMBs have never been in a better position to capitalise on the billions of dollars SAP have spent on R&D in recent years and take advantage of the industry standard best practices that SAP have honed through over 30 years of working with more than 10,000 customers across the globe.

Spend a minute taking a look at the presentation and see what you think.

PS. There is an audio commentary so turn your sound on.

PPS  This is part of G3 Global entry to the SAP Best Practive Challenge 2011 so positive feedback is most welcome.

SAP All in One for small to medium sized businesses – Product Overview

SAP Business All-in-One is an integrated, business wide, system support solution that has been designed with small to medium sized businesses in mind. It has evolved from SAP’s vast experience of working in Enterprise Resource Planning space with over 10,000 companies, in more than 50 countries across the globe.

Standard best practices have been distilled by industry experts from more than 30 years of working in the field to form a fully configured core package that greatly reduces implementation times and costs whilst maintaining SAP’s legendary quality standards.

The SAP Business All-in-One solution can help small to medium sized companies to improve financial management, maintain operational excellence, and enhance competitive agility so that success, even in times of economic uncertainty, is more assured.

Take a look at this short overview film (there is an audio sound track, so turn sound on) to get a flavour of the solution and see what all the shouting is about.

Data Matching Engine

It’s becoming increasingly harder to find the data we’re looking for. Sometimes, even Google or Bing searches can fall slightly short, and we’ll find ourselves having to filter through many result sets to eventually find what it was we were actually looking for. In the business world, this is not dissimilar – the act of having to find and match data. This is by no means a simple task, and grows exponentially harder in proportion to the size of the dataset in question. As an example, how many times have you found yourself in a situation where you needed to import a file filled with overwhelming volumes of data, and somehow magically map that data to meaningful entities in your own business? It should be simple right? On one side you have a set of data(that entity it is you’re looking to match), and on the other side you have a list of possible matches. This would be a lot simpler if what was on the left and right were exact matches, but as both you and I know, this is very unlikely situation, and would almost be classed as utopia! So, more often than not, we’d find ourselves having to employ the expertise of a bespoke written piece of software to do the hard work for us. However, even then, its that piece of software genius, that’s only useful within that particular context, in that particular domain – so not a very portable solution.

So how do we overcome this problem? Wouldn’t it make sense to invest time and knowledge into a component that, given a set of rules, will be able to match similar datasets together? Well, thats exactly something that G3 Global have done.  We at G3 Global, have recognised that there is a common problem out in the industry today, where importing and matching data is a problematic and time consuming process. So what our software geniuses have done is, develop the G3 Matching Engine that is capable of finding similarities in data, based on proven complex techniques and algorithms.

Given a set of user-defined rules and two data sets, we are able to find and rank the most similar items in each data set. The engine allows the user to define how they want the data to be compared, and how important each comparison is in relation to the others. One scenario in which this has been proven is matching customer  dataset from the source sales system in the business.The scenario we faced was, a system which supplied a master list of customers(the left hand side of the data comparison, also known as the source), and a 3rd party, which supplied customer information in its own format(the right side of the data comparison, also known as the target), and we needed to determine which customers were the same, and which customers were new (finding and matching similar records). The end result was displaying all customers in the destination data set that were similar – based on the rules and associated weighting provided to the matching engine – for every customer in the source. Each match is given with a percentage ranking, allowing quick comparison of results.

The engine does not simply compare texts using “dumb” starts with or contains checks, but rather calculates how similar they are. This allows the engine to handle typographical errors, spaces, and typical data entry issues that usually cause problems for the simpler comparisons discussed above.

The image below illustrates the concept.

Data Matching Engine Illustration

This might be better explained by referring to real world business areas. Off the top of my head, I can think of three business spaces where this type of tool could be useful:

  1. Music Sales
  2. Publishing
  3. 3rd Party Logistics

All of these areas mentioned above, assuming we’re talking about the act of someone selling goods on their behalf, has the model of supplier and vendor.Whether that be an example of iTunes selling on Univeral Musics’ behalf, or perhaps Amazon selling on O’Reillys’ behalf, or any other vendor selling products on a suppliers behalf. One thing is common between all of them, and that is the vendor needs to report back to the supplier to notify them what has been sold. Whether that be for the purpose of a suppliers re-filling their stock, or simply for the vendors to collect their share of cash, as a fee for acting on the suppliers behalf, either way, some matching of supplier and vendor data has to occur.

By using the G3 Matching Engine, you’ll be able to easily and effortlessly, load both datasets – the vendor master dataset, and the suppliers dataset – and determine which items are being referred to, by analysing the similarity of data between the two data sets. You’ll be able to configure which elements of the data you’re more interested in, and you can even assign a preference, or weighting to the elements. So for example, if you’re trying to match addresses, you might find matching on post code is more important than finding a match on Line 1 and 2 of the address details.

Obviously, this matching isn’t just restricted to the three business areas mentioned above. It can be applied to almost anything where you need to find similarities between two sets of data, given that there are similarities that exist.

Adopting Test Driven Development using ABAP Unit

This post isn’t intended to be a description of how to use ABAP Unit, it is rather an effort to express my personal experience with trying to adopt Test Driven Development as one of my key development practices. As I currently develop in SAP’s ABAP I have used ABAP Unit as my tool for running tests, which is just a variant of xUnit descended from Kent Beck’s original implementation in Smalltalk. However, the testing framework is a minor element when approaching Test Driven Development. The practise turns your development process on its head, and it isn’t an easy thing to learn how to do well.

To start with, it would be helpful if I explained what it’s all about, as I hope to introduce the concept to ABAP programmers who haven’t come across it, or don’t understand how it is supposed to work. The principle of Test Driven Development (henceforth referred to as TDD) can be summarised in four steps:

  1. Write a test to check a unit of code does what it is supposed to
  2. Write only enough code to make the test pass
  3. Immediately refactor the code under test to remove duplication
  4. Repeat steps 1-3

This is often confused with Test-first Development, which misses out step 3. Many people who would say they are doing TDD are actually doing TFD because they don’t refactor. One of the core benefits claimed about TDD is that it allows you to improve the code and design by refactoring your basic solution early.

An important point is that the four steps should be a fast cycle. The time between writing a test and getting to to pass should ideally be less than a minute or so, because you only write enough code to make the test pass. This also implies that code is being broken down into units that don’t do too many things. The developer is looking for fast verification that each code unit is working correctly. Also, the resulting unit tests provide a specification of what the code is supposed to do.

Once you have a test that passes, you can refactor the code immediately and be confident that the code is still functionally identical. You refactor early to get rid of any sloppy coding that you introduced while getting the test to pass, with the confidence that your tests will verify that the functional properties remain the same.

What TDD is targeted at is the fear of making changes to existing code, even if it is in desperate need of improvement. Code that has been functionally working for some time is changed as little as possible in the belief that changes will risk breaking functionality. Often this belief is reinforced when someone makes changes and breaks something, leading to very cautious changes when functionality is added or bugs are fixed. The problem in the long term is that the state of code that is added to and changed over several years deteriorates until it is a real chore to work with. What I’d call the “but it works!” argument tends to stick even if everyone agrees that Something Ought To Be Done.

The fear really comes from ignorance. You don’t know what the program you’re changing really does, or you last worked on it two years ago and just can’t remember the details of the specification or the last thing that was done to it. The application of automated tests seeks to remedy this problem by providing a reliable regression mechanism that records exactly what a given piece of code is supposed to do, and tells you if functionality has been broken.

To get a bit of perspective on the benefits from the “Agile” world, where TDD is often considered a core practice for developers, I can refer to the work of Scott Ambler. He is a key personality in the Agile world, working for IBM under Rational as Chief Methodoligist for Agile and Lean. He surveyed a number of Agile teams, asking about their experiences in adopting TDD, and the results were published in Dr. Dobb’s Agile Update of January 2009. This is useful for looking at how teams evaluated the benefits they had obtained from TDD:

The survey explored the benefits that respondents were actually experiencing with TDD. When it came to acceptance TDD (requirements-level TDD) the top three benefits were improved specification accuracy (73% response rate), increased ability of software developers to actually change software (66%), and increased quality (61%). For developer TDD (design-level TDD) the top three were increased ability of software developers to actually change software (98%), increased quality (92%), and increased ability to react to stakeholders’ changing needs (72%).

Here I am mainly concerned with Developer TDD, because that is the kind of testing that ABAP Unit is intended for. The last point is particularly relevant, as it will impact a teams ability to deliver results to the customer, which is the ultimate point of developing software in the first place.

Now, while it is easy to comprehend what TDD is, learning how to do it is a different thing entirely. The assumption in the above description is that you know how to write the tests that will cover a code unit’s functionality. This is not actually an easy thing to learn, as I found out in my efforts to get code under test.

How difficult is it to adopt Test Driven Development?

Initially, I didn’t really know what I was getting into, but it is worth pointing out that getting going with TDD as a practice is not easy and Agile teams where TDD is the norm don’t find it easy to learn in general.
In the Dr. Dobb’s survey, Ambler asked why TDD hadn’t become more widespread:

So, why aren’t people doing more TDD? First and foremost, TDD requires discipline and it requires skill. When asked about the difficulty of learning acceptance TDD, 39% said it was either very difficult or difficult and 49% said the same of developer TDD. The survey explored four potential issues which could be hampering the adoption of TDD, and all four seemed to be having a significant impact. The lack of TDD skills had the largest impact followed closely by a lack of regression test suite for existing functionality. The other two factors, lack of training and education (which clearly has an impact on skills) and a waterfall culture within organizations trailed closely behind.

Here I am dealing with Developer TDD, which is mainly automated unit testing. I can verify from personal experience that discipline and skill requirements for TDD are not trivial. Like anything that is worth learning, it will take time. Writing test code first is such an unfamiliar practice that initially, it will seem too easy to revert to habitual behaviour. Even if you do manage to make yourself write test code, the code you are working on, which is probably legacy code, won’t necessarily make itself easy to test.

Lack of TDD skills generally in an organisation is also something I can appreciate as a barrier to adoption. In my case it just slowed me down a lot, but I was also strongly motivated to learn new skills. However, a developer less strongly motivated to pick up new techniques may not go forward unless there is a strong precedent of TDD practice in the organisation. If you don’t have an experienced colleague to guide you, there is going to be a lot of time spent figuring things out, frustration and falling back on familiar habits, and initially TDD seems to mean more work. Mentoring or training cannot be underestimated for encouragement and advice, and reassurance that the effort eventually pays off.

I can also verify that the lack of regression tests is a big problem. You have no examples of test classes to learn with, and because the code hasn’t been got under test, it isn’t going to be designed with testing in mind. This is where I have had most trouble in applying TDD on legacy code – it wasn’t obvious what the path was to getting code under test, and that is where some help from an experienced TDD practitioner is invaluable. I had to accumulate the experience over a longer period instead of being accelerated by a helpful colleague.

I don’t currently have a major problem with “Waterfall culture”, because we have many supporters of Agile methods at G3. Also, determined developers aren’t going to give up even if they have to work under waterfall planning. However, in general a waterfall culture will mean that methods associated with Agile are unlikely to get much attention.

It is worth reading through the whole Agile Update article for some background on TDD and some of the challenges agile development teams have with adoption. If Agile developer teams find this difficult, it is going to be even harder for the typical ABAP programmer, who has typically worked alone and is not used to

First exposure to the idea of automated unit testing

So what was it like for me? My introduction to automated unit testing began with some hints from a project manager colleague who had worked on other projects of various kinds and knew a fair bit about agile methods and the use of automated unit testing. I had already heard about Extreme Programming (XP), but only that it emphasised regular pair programming sessions during development. We had a copy of Extreme Programming Explained in the office, and after I had read that some idea of the goals behind automated unit testing. I was intrigued by the idea but I didn’t know how to approach it.

Perhaps the most obvious difficulty I had was that there wasn’t actually any ABAP developer I could ask for advice. There was no-one who could sit down with me and take me through examples, or pair-program on a problem to illustrate. As I understand now, only a developer with a decent amount of TDD experience will be able to look at any programming problem and have a feel for where to start, particularly if you are working with code that doesn’t have any tests.

I was essentially the TDD pioneer, and the apparent online interest in TDD in the online SAP developer community was not that encouraging. On SDN there are two wiki pages and a handful of blog entries. Enough to get a bit of a start, but certainly not the level of discussion that there should be. Most of what I have learned about TDD at a more advanced level has been from my own exploration or sources outside of the ABAP world.

At first I had a little play with ABAP Unit as a tool, without understanding how it should be used. I got the basics of creating local test classes and executing their test methods. Initially it just seemed like a handy way to execute subroutines or class methods without having to quickly whip up a test program. Initially I used the test tool to execute units of code while using the debugger to analyse what was going on. However, I was missing the main point of the tool, because I hadn’t actually automated the testing element.

ABAP Unit provides a class called CL_AUNIT_ASSERT which has methods to test the values of variables against expected values, for example ASSERT_EQUALS tests if the expected and actual values are the same. If a condition isn’t satisfied you get a report in the ABAP Unit result view. Without making used of the assertion class, I had merely made it easier to manually test units of code at an earlier stage, well in advance of these units being incorporated in a running application. If you don’t code any tests, ABAP Unit can only report fairly serious problems raising exceptions.

Looking back, this is just a problem starting off without any guidance on where to start, or it may have been a tendency to just want to figure things out.

How do I write tests?

I didn’t get a great deal of benefit from ABAP Unit at all until I read Test Driven Development: By Example by Kent Beck, originator of the unit testing framework in Smalltalk (sUnit). This book actually explained the philosophy behind TDD, and how it can empower programmers by removing fear of refactoring code. I also found out how it was supposed to work, with the four steps summarised above.

Once I understood what I was trying to achieve, the problems inherent in writing unit tests in an ABAP application server environment became apparent once I had got the hang of writing tests that worked properly.

The examples in Kent Beck’s book did not involve a database, and usually database connections are not part of unit testing because in most programming environments you can’t guarantee a database will be available when tests run. Because the ABAP environment depends on there being a database connection, the connection is always there and many routines depend on SQL queries embedded in business logic code.

ABAP developers get into the very comfortable habit of spreading similar database code everywhere because it is so quick to write queries, but this causes problems when you want to write tests. I was working with a lot of code which was not always amenable to being tested because of the number of database dependencies that were fiddly to control in test setup code. Because of this, most of my earlier tests are written assuming certain data is present in the database. Without that data the tests just all fail.

I made some attempts to work round this by setting up database records in a known state in the setup fixture, then removing them at the end of the test in teardown. Although this works, it is potentially risky, and the setup code you have to write is tedious and time consuming, particularly if several tables are involved. I find that unit tests that rely on database data are still worth writing, as it is better to write some kind of test rather than none, but they are only going to be meaningful on one SAP system and only as long as the data you use remains unchanged. You won’t be able to trust your old tests as a regression suite, and there might be a significant effort in getting them all to work again if you revisit them several months later.

The best solution to the database access problem is to refactor code so that all SQL is kept separated from business logic you want to test. You should at least be able to feed test records into a subroutine that uses database data, although ideally it is worth using a class to encapsulate SQL, coded to an interface so a test implementation can be substituted that does not depend on the state of the database. Whenever I actually achieve the separation of the SQL code and just work with mocked up data or mock implementations of Data Access Objects, the speed at which I can write tests accelerates considerably.

Limitations with ABAP development tools

It is true that programmers generally don’t like to write more code that they have to, and particularly repetitive “boilerplate” code. The best modern development tools enhance the productivity of the programmer by completing the tedious coding tasks. This is not a strong point of the ABAP editor, and for TDD there is a test class generator for global classes in Netweaver 7.0, but nothing for generating tests in standard ABAP programs. Also, when it comes to adding test methods there is nothing that can help you there. For a language such as ABAP, which requires you to define separate DEFINITION and IMPLEMENTATION sections, a function to add a test method body with its definition would save quite a bit of typing, and navigating between the two class sections.

I have found that this makes the writing of tests more work that it needs to be. It is possible to save time by using code templates defined in the ABAP editor control, but intelligent code generation is something that is absent. If you ever delve into Java and use Eclipse or IntelliJ Idea, you realise how primitive the ABAP editor is.

Unfortunately I think ABAP developers are stuck with the the situation, as there is no possibility of extending the editor with any plugins or enhancements.

In Conclusion

Experience has shown me that TDD can open up a huge number of issues with the way you write code, and this can either lead to frustration, or an opportunity to learn about or develop new techniques, and change bad habits. Also, unless you are in the position of being able to start from scratch on something, the main challenges are going to come from getting legacy code into a testable form, and this will be more difficult if you haven’t seen an example of a program that has had TDD applied to it. I found the book Working Effectively With Legacy Code very useful as a guide for learning how to get legacy code under test. In fact, it is probably worth reading this book directly after you’ve got the concept of TDD, because this is what most programmers will be working with if they are starting out where there is little or no history of TDD practice in their team or department.

It does take a long time to get into the discipline, but eventually you get to a point where you realise the tests you have built up are making your life a lot easier, and you spend considerably less time staring at the debugger. I’ve heard this referred to as a little “aha” moment, probably in a Robert Martin interview, where you suddenly realise that what you’ve just done would have taken an extra 5 or 10 minutes or even ballooned into half an hour if you weren’t doing TDD.

Finally, I’ve found that it can make quite boring coding changes more interesting because there is the added challenge of getting something under test. This really improves focus when I have to deal with minor problems that don’t really engage me on the first look.

I’ve barely scratched the surface with TDD, but I hope it may encourage other ABAP developers to look into it and give it a try.

Mobile workforce management on Android

Coming to a mobile device owned by your company soon. Mobile workforce management on a Android powered phone. A G3 Global Labs production.

Android mobile workforce management from g3global on Vimeo.

Credits:

Smartphone sales have outpaced traditional pc sales at the end of quarter four 2010. This shift in sales to mobile devices should make each business think how to take advantage of this change. At G3 Global we know how to help your company harness this technology.

SAP All in One has been positioned as Market Leader in Gartner Magic Quadrant

SAP All in One has been positioned as Market Leader in Gartners  “Magic Quadrant for ERP for Product-Centric Midmarket Companies”. SAP Business All-in-One is recognised as a market leader for both its “ability to execute” and its “completeness of vision”. See SAP press release