Continuous Integration as Quality Reflection
One of the most common question in moving towards Agile Development is “Where should I start from?“. If you’ll ask me, setup a Continuous Integration (aka “CC”) would be the first thing you should start with.
Step 1 (Check for compilation bugs): Code Quality ~= 30%
The CC should be able to identify check-ins to your source control, get the latest source and compile it. The output should be either “green” (Everything compiles successfully with 0 warnings) or “red” (more than one warning or compilation errors). In addition to the fast feedback, the output should also include the files that were changed from the last build (and by whom, so people could know where to look).
The immediate value is priceless. the ability to SEE whether your source-code is stable enough to allow other programmers perform Get Latest and continue their work and the “fail-fast” attitude can save you a lot of time in the long run. It’s important to realize though that even if the code compiles without warnings, it still doesn’t mean that you could count on the quality of the code.
Step 2 (Check for component-based quality): Code Quality ~= 70%
If you can go one extra mile, write a few automated tests (via one of the available XUnit frameworks) for your components. This means that you are able to inject the component’s dependencies from the outside and simulate mini use-cases on component’s level. This step is crucial even if you write those after the code itself was written. Let the CC run them if Step 1 is OK. This should allow you to catch the majority of your bugs (I’ll leave the “how to write good tests” to another post). If all is green, you know that the system behaves as expected, at least to some extent.
This step is not trivial as it requires you to design for testability and invest in proper testing. Don’t let go of this step though, automated tests on this level will make your life much easier. It will take your code one (major) step ahead in “write code that could be changed”. Agile is all about that state of mind.
Step 3 (Check for integration-based quality): Code Quality ~= 80%
Now that you’re components are behaving as expected, you should try to write a few (automated, of course) tests that simulate the entire flow of 2 or more components (DB is a component as well) in the system. As the system grows and more uses cases are added, you should try to improve these tests as they give a solid proof that the SYSTEM works.
Step 4 (Make everything visible): Code Quality ~= 90%
The state & quality of your source control should be visible to the Team and Management as you want to insure IMMEDIATE response time in case someone check-ins a low quality code (on any level). Fixing a failing test three days after the change itself is a bad symptom of low visibility or low perception, by the Team, regarding the importance of the quality of the system.
Step 5 (Automated deployment): Code Quality ~= 95%
After successful build you would like to deploy the latest source on a dedicated environment which the developers could play with before deploying to another (testing?) environment. This won’t be a stable environment, but at least it will give a quick look at the current state of the system – the way customers would see it.
Step 6 (Procedures checking): Code Quality > 95%:
You can add many more checks to the flow, such as Tests Coverage or FxCop. Leave those to the end. From my experience, Time .vs. Value in these features will vary from team to team. You’ll gain much more from investing in Steps 2-3.
Semingo CC:
Each developer & manager on our team have a CCTray(the little red circle in the little picture above) which is either Red(source control is damaged), Yellow(Build in action) or Green(Life is sweet). We’re using Cruise Control.Net, CCTray, MSBuild (and TFS plugin) and NUnit to perform all of the above.
A few teasers:
* Image of Steve Urkel (from the famous Family Matters TV series) is shown for failing build.
* On the right you can find Pasha (with a V sign I’ve added), one of our finest hackers modeling a successful build. You can also notice the 582 green tests (including Integration tests) and 2 changes made by Sagie since the last build.
* Going to NUnit Details, you can get the full details:
I had to cut the pictures in order to keep a sane width for the post, but you can get the drift.
btw – Aviel, yet another Semingo hacker add a “Doh!” (Simpson) each time the CC is red on his computer. It can be quite funny (and scary, if fully concentrated on code).