Translate

Sunday, 30 December 2012

Story boards

Story boards are extensively recommended for use in an Agile team but where was this idea used first?

Email your answers to me. It will be fun to interact! :)

Tuesday, 25 December 2012

Removed malware

When I updated my blog with program code from another decade, Blogger complained of malware. Removed all link references from earlier blog that was embedded in the program codes.

Friday, 21 December 2012

20 years + in software development ! ;P

Realized that I started coding/developing software two decades ago. Still remember every line of code. Posted on the side bar and the bottom of the blog.

Friday, 30 November 2012

At Patna for the OLPC Demo - 27th - 29th Nov 2012

Demo of the OLPC Laptop



Leadership Training on the Use of ICT in Teacher Education in Bihar: Strategic Workshop



Demo of the OLPC laptop 


Wednesday, 14 November 2012

BDD with NBehave starter example

Here is a quick help for BDD with NBehave beginners.

Also refer to this presentation by me on BDD and UADD at the Agile NCR conference  - BDD and UADD with Slim

The .feature text  file that describes the scenario(s) and which gets executed by NBehave !


The ActionSteps that define the actions proposed in the .feature file above in the BDD format of Given, When, Then.


And the production class,

 public class Calculator
    {
        private int result;
        private int one, two;
        public void Enter(int o,int t)
        {
            one = o;
            two = t;
        }
        
        public void Add()
        {
            result = one + two;
        }
        public int Value() {
           return result; 
        }
    }

Below is the nbehave results



Monday, 12 November 2012

Behavior Driven Development with Tumbler

Will elaborate on comments and questions to this post :)

More on this can be found at - http://ravichandranjv.blogspot.in/2010/05/decision-table-in-slim.html

Also refer to this presentation by me on BDD and UADD at the Agile NCR conference  - http://tinyurl.com/d6xjfox


import static tumbler.Tumbler.*;

import org.junit.runner.Result;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
import tumbler.Scenario;
import tumbler.Story;
import org.hamcrest.BaseMatcher;
import org.hamcrest.core.IsEqual;
import org.hamcrest.core.IsNot;
import org.hamcrest.core.IsNull;
import org.hamcrest.core.IsSame;
import tumbler.JUnit44TumblerRunner;
import tumbler.TumblerRunner;

@RunWith(JUnit44TumblerRunner.class)
@Story("Generate genome sequence from values passed")
public class GenomeTest {
@Scenario("ATGAC")
    public void shouldGenerateCorrectPatern() {
        Given("A Genome sequence");
        GenomePattern gp = new GenomePattern();
        Object someValue=null;

        When("Genome pattern is to be generated");
        Result result = gp.generatePattern();

        Then("expect ATGAC");
        assertNull(result); // Making test pass as per TDD
    }
}

Friday, 12 October 2012

Agile series V - TDD, UADD and BDD, briefly

Briefly put, in TDD, you write a test first, if the test fails, write only that much code to make it pass and if the test passes, write another test. The goal is to write a new unit test once the previous test has passed. Let the design evolve from this sequence.

Once the code is stable, brush it up with some re-factoring and showcase it (or present it) to  the tester for user acceptance tests. If the tester comes up with bugs or with exceptions, go back to the previous step of writing more unit tests to be able to determine what code should be written for the user acceptance to happen!

In UADD, start backwards. Get the UAC and then start your TDD ! Simple !

BDD is just a step further ! :)

http://ravichandranjv.blogspot.in/2012/11/bdd-with-nbehave-starter-example.html
http://ravichandranjv.blogspot.in/2012/11/behavior-driven-development-with-tumbler.html

Happy TDD & UADD !

Agile series IV - after refactor!

The method "Subtract" (It was "Substract" initially. In this snapshot, you see a red double dash under the "t" because I had corrected the spelling but not rebuilt it!) was not called because of misspelling and the resulting coverage is below!


Added try-catch and refactored all the return statements into individual statements


After full refactor..




Agile series III - UAT with Slim/Fitnesse

Failing tests because user input is also negative! Wrong expectations ?


3 Failing tests and 2 exceptions! Wrong expectations or wrong code?


Thursday, 11 October 2012

Agile series II - The not-so-perfect world!

The previous post is all about how perfect the software world is, given perfect behaviour of code! But, nothing in our knowledgeable world is perfect because that is the reason everything, in our known world, constantly evolves or "changes".

And so, we will start with the "assumption" that our code is perfect and start giving it all kinds of "whacky" inputs! Whacky means that we do everything that goes against the expectations of the "perfect" code but with the goal of achieving 100 % code coverage ! For instance, we will provide a combination of negative and positive and zero values to the domain class and see how it behaves! Simple !

And this is what the user, who did not create the code and therefore, does not know. So, here ends unit testing and  begins User Acceptance Testing where we supply the code with all kinds of inputs and the entity that will do it should be some entity that did not write the code - it could be the end user, the customer, the tester or just about anybody.

If there is a user interface, we could use the input mode to take the input; if not, we supply it through an automated testing tool like Fitnesse!

And from here starts testing for exceptions, wrong inputs and unformatted inputs.

The passing UAT test with FitNesse/Slim framework is below


This is the fitnesse way of doing it! Write a separate fixture class and test it with two public fields, firstValue and secondValue, and have different methods for testing. That is, just to do UAT you need a separate Fixture class written by the dev.

The Slim way is straightforward. Just consume the same domain class for UAT!

Below is the Slim script for the same class that had been unit tested and for which the code coverage was 100 %.



Contd...in subsequent posts.

A simple coverage example - NCover 4 - Agile series I

The failing test, TestMultiply, decreases the coverage % plus the two methods, Subtract and Divide, do not have unit tests, which also decreases the coverage. 


    [TestFixture]
    class TestCoverage_Class2
    {
        Coverage_Class1 initCoverage = new Coverage_Class1(55, 12);
        [Test]
        public void TestAdd()
        {
            Assert.AreEqual(67,initCoverage.Add());
        }
        [Test]
        public void TestMultiply()
        {
            Assert.AreEqual(60, initCoverage.Multiply());
        }
    }

// Domain class being tested

public class Coverage_Class1
    {
        int firstValue, secondValue;
        public Coverage_Class1(int a, int b)
        {
            firstValue = a;
            secondValue = b;
        }
        public int Add()
        {
            return firstValue + secondValue;
        }
        public int Multiply()
        {
            return firstValue * secondValue;
        }
        public int Subtract()
        {
            return firstValue - secondValue;
        }
        public int Divide()
        {
            return firstValue / secondValue;
        }
    }

Write the two tests for the additional two methods, Divide and Subtract, with one of them a failing test and the coverage looks like this:



Make them all pass and voila, 100 % coverage  !




Work around with the Threshhold values and you will increase your own coverage capabilities ! :) Happy Coverage! :)


Wednesday, 10 October 2012

New in NCover - Change Risk Analysis & Predictions (CRAP)

This coverage report for the previous post

Max Crap Score - 6 (Max. - 930 calculable of 999)



Max complexity


Saturday, 6 October 2012

Thread.Sleep is not the same as await

Note: Since Blogger eats up less than and greater than symbols, please replace async Task with Task of int as in generic types.

The most common mistake that many make about asynchronous processing is to think that Thread.Sleep means asynchronous. To demonstrate this is the below code, which is a "buggy" code because of the Thread.Sleep call.


// The code

using System.Threading.Tasks;

namespace Net45.UnitTests.Samples.Jv
{
    public class ClassUnderTest
    {
        public static int? taskId;
        public static string taskName;
        public static int result;
        public async Task "less than" int "greater than" AddWithTask(int a, int b)
        {
            await Task.Factory.StartNew(async () =>
            {
                taskName = "AddWithTask";
                taskId = Task.CurrentId;
                result = await add(a, b);
            });
            return result;
        }
        public async Task "less than" int "greater than"add(int a, int b)
        {
            int x = 0;
             Task.Factory.StartNew( ()=>            
            {
            x = a + b;
            taskId = Task.CurrentId;
            System.Threading.Thread.Sleep(20); // Without using this statement you will see the tests failing (as shown in point 5 in the previous post), the synchronous task continues its execution giving the impression that using Thread.Sleep() makes for asynchronous processing (because if you use the  code without a test, the code will compile and execute correctly but not with the expected result), Await makes the caller receive the callback result and not Thread.Sleep. 
To see it in action, modify the async method above to look like this
public async Task 
"less than" int "greater than" add(int a, int b)
        {
            int x = 0;
            await Task.Factory.StartNew( ()=>            
            {
            x = a + b;
            taskId = Task.CurrentId;
            //System.Threading.Thread.Sleep(20);
            });
            return x;
        }

            });
            return x;
        }
        public async Task "less than" int "greater than"returnAdditionResult(int a, int b)
        {
            int x = 0;
            x = await add(a, b);
            return a+b;
        }

    }
}


// The test class

using System;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;
namespace Net45.UnitTests.Samples.Jv
{
    [TestFixture]
    public class AnthonySteeleClass
    {
        ClassUnderTest cutHandle = new ClassUnderTest();
        int? taskId;
        [SetUp]
        public void init()
        {         
            Console.WriteLine("Value of x is {0}", ClassUnderTest.result);
            Console.WriteLine(ClassUnderTest.taskName + " id is " + taskId); // To be used by yourself as you want to.
            Console.WriteLine("add method task id {0}",ClassUnderTest.taskId);
        }
        [Test]
        public async void TestAdd()
        {
            int answer = await cutHandle.AddWithTask(40, 2);
            Assert.That(answer, Is.EqualTo(42));
        }        
        [Test]
        public async void TestAsyncLambdaTask()
        {
            int answer = await cutHandle.AddWithTask(40, 2);
            Assert.AreEqual(42, answer);
        }
    }
}

When Synchronous is ahead of the asynchronous...

When Synchronous is ahead of the asynchronous...make the asynchronous call wait ! :)

1, 2, 3 & 4. The unit test, TestAdd fails because it calls the async method AddWithTask which, in turn, calls the async method add.
5. This is  because the  async keyword does not ensure asynchronicity; the "await" keyword does that making sure that the method call awaits 'asynchronously' for the method call to complete.

To make the test pass, add the 'await' keyword to the Task.Factory.StartNew as in the AddWithTask method.

Please refer to the next post for the "buggy"code and the test to find the bug.

Happy unit testing with NUnit ! :)

Thursday, 4 October 2012

A sneak preview - Sample NUnit async test

Since NUnit is being made aware of C# 5 new features, here is a sample unit test on async and await.

The current NUnit downlaod may not work so wait for some time before a stable build is announced.


using NUnit.Framework;
using System.Threading.Tasks;
using System.Threading;
namespace Net45.UnitTests.Samples.Jv
{
    [TestFixture]
    public class AsyncTest
    {
        int x = 0;
        [Test]
        public async void testAddition(){                    
            Assert.AreEqual(15, await returnAdditionResult());
        }
        [Test]
        public async void testAdd()
        {
            Assert.AreEqual(17, await add(9,8));
        }
        private async Task add(int a, int b)
        {
            return a + b;
        }
        private async Task returnAdditionResult()
        {
           return await add(9, 7);        
        }
    }
}

Wednesday, 3 October 2012

Async and await - C# 5


using System;
using System.Threading;
using System.Threading.Tasks;

namespace AsyncAwait
{
    class Program
    {
        static int? addTaskId, printTask,taskMethod2Id;
        static int x;
        public static async Task TaskMethod2()
        {
            Console.WriteLine("Task Method 2 called");
            await Task.Factory.StartNew(() =>
                {
                    printTask = printTaskId();
                    Task.Factory.StartNew(()=>
                        {
                        x=add(9,8);
                        addTaskId = Task.CurrentId;
                });
                });
            return Task.CurrentId;
        }
        static int add(int a, int b)
        {
            return a + b;
        }
        public static async void MainTaskMethod()
        {
              await Task.Factory.StartNew(async () =>
                {
                    taskMethod2Id = await TaskMethod2();
                });
        }
        public static int? printTaskId()
        {
            return Task.CurrentId;
        }
        static void Main(string[] args)
        {
           MainTaskMethod();
           Thread.Sleep(15);
           Console.WriteLine("Task ids are {0} and {1} and value of add result is {2}", addTaskId, printTask,x);      
            Console.Read();
        }
    }
}

1. taskMethod2Id  will be null because the Main() method cannot be async-ed and hence the result cannot be await-ed.
2. Remove or comment the "Thread.Sleep(..) " call and see how it works! 
3. To use await inside a lambda expression, mark the lambda with the async keyword.
4. If you remove the await keyword from inside the TaskMethod2

            await Task.Factory.StartNew(() =>
                {
the output for addTaskId will be "3" and for printTask, "2" and if you use await, it will be "2" and "1". 
5. The usage of the async does not mean asynchronous processing, of the method or the lambda,  automatically but that you can enable "await"-able states within the method or the lambda expression. 
Happy C# 5 programming! :)

Saturday, 22 September 2012

About OLPC


The One Laptop per Child non-profit develops a low-cost laptop—the "XO Laptop"—to revolutionize how we educate the world's children. Our mission is to provide educational opportunities for the world's most isolated and poorest children by giving each child a rugged, low-cost, low-power, connected laptop; and software tools and content designed for collaborative, joyful, self-empowered learning.
As of March 2011, we have produced XO laptops for roughly 2 million children around the world, the majority of them in UruguayPeruRwandaHaitiMongolia and the United States. These laptops all run Sugar and Fedora Linux, and have customized software and content builds developed by their national deployment teams in collaboration with OLPC staff. We maintain a regular update of deployment information.


For more info, please visit this link - http://wiki.laptop.org/go/The_OLPC_Wiki

Wednesday, 12 September 2012

Dr. Walter Bender demonstrating the awesome laptop for kids!


Dr. Walter Bender, MIT, demonstrating his laptop for kids at the Agile Goa 2012 conference Touch screen, gesture aware, unbreakable. Played a game on it by just shaking the device to all sides ! Absolutely incredible for kids. Wish Indian schools and pre-schools would go for it. :)

Tuesday, 4 September 2012

Cause - Effect

Orient your requirements 

The implementation model - Ay, ay, ay, ay !




Saturday, 1 September 2012

Organizational facade - First Point of contact

A facade, as a design pattern or as an architectural artefact or as a representation of an entity, serves an important role - that of being the first communication point for the external world.

An organization's first point of physical contact for the external world is with the front office or the telephone operator/reception. An organization can get so easily branded by the front or facade it puts out for the external world. All marketing efforts may benefit from the correct portrayal of this facade.

Thursday, 30 August 2012

Tuesday, 28 August 2012

Agile Goa 2012 conference

I had a great experience at the conference on Agile by ASCI for the Goa university, with the Computer Society of India, that was wonderfully organized at the Talegao Community Centre, Goa on 24th & 25th August, 2012, in true Agile spirit with the students doing a great job in coordinating between sessions and helping out with my session on "Respect in the Agile context". A great team effort.

Thanks to ASCI, Computer Society of India and Goa university for carrying forward the flame of the Agile spirit into universities and institutions.

Special thanks to Surbhi, Goa university, for taking that extra effort to take these photographs and to Prajyot Mainkar.






Tuesday, 14 August 2012

Guidelines for Better Unit Tests

http://www.infoq.com/news/2009/07/Better-Unit-Tests
    1. One Assert per test (where possible). 
    2. If there are any "if else" inside a test, move the branches to individual test methods. 
    3. Methods under test, if they, too, have if else branches, the method should be refactored.
    4. Name of the method should be the kind of test. For instance, TestMakeReservation is different from TestMakeNoReservation().
Charlie Poole, author of NUnit, rewords one Assert per to test to one “Logical Assert” – saying “Sometimes, due to a lack of expressiveness in the testing api, you need to write multiple physical asserts to achieve the desired result. Much of the development in the NUnit framework api has been out of an attempt to get a single assert to do more work.”

Monday, 6 August 2012

Respect in the Agile context

From a discussion in LinkedIN's  Agile and Lean Software Development

Respect in Agile is: 

o Comunicating clearly in a way that leaves no possibility for doubt on intent 

o Communicating honestly, but with tact and care for each other's feelings 

o Working to continually improve the way the team functions and interacts 



Working to continually improve the way the team functions and how they interact with each other." Is that

clearer/communicate that point?  (Jan McCleery)

Contributed by Jan McCleery - Here is the link to her blog for more - "What is Respect?" 
http://duckpondsoftware.wordpress.com/2012/07/19/what-is-respect/

Friday, 29 June 2012

Tuesday, 26 June 2012

Had a good time at TW hosted VodQA G'gaon 2012.

Took my own brunch of sandwiches for various & personal reasons, which on hindsight seems to have been a good idea because of the time that it took the hosts to resume the session! :) The guy operating the video camera came late after a 'free' lunch!:P And the session on was Xebia's, a NCR competitor for the host! 

My session was, as usual, eaten out by lengthy primers, introductions, the presenter-remote malfunctioning ...! :P

The most enjoyable was a game. More than the game, the fun was in watching a female rushing in for the game, which was to be played with teams of 5 and we already had the teams formed but she joined ours named "Dog" and made a cat sound without even waiting for the instructions (how on Earth did she know how the game was to be played if she came in late? I will ask her the next time I see her, if there is one!)

Another interesting session was one on "ethical (erm!)" hacking by TW. The presenter showed the audience how you can steal passwords, even get into bank accounts and all that stuff that really appeal to the young gen. Erm!

Best part of the whole exercise for me was that I had a peaceful sleep after reaching home. Slept for about 18 hours with the intermediary breaks for dinner, a movie, twitter etc. :P

TW hosted VodQA conference, Gurgaon, June 23, 2012


It was a conference hosted at the TW premises on a Saturday so the audience was not really "door crashing" but maybe it was not meant to be that way!

My session on "Game Testing" http://prezi.com/wof1dvtciw_r/sudoku-31/ went okay; a game by TW right after lunch meant a cheerful time for all and another on Hacking, though was out of context throughout as it concentrated only on hacking and not on "Testing as a hacker".

Overall, a good outing better than the boring Saturdays watching TV!


Ps: Will post pics as soon as they are shared by the host.



Web Workers

Monday, 4 June 2012

Theory-Simple NUnit test!

Make sure you notice the array size and the two test names...self-explanatory tests!




Effective planning & retrospectives

Effective planning is to be prepared that there will be contingencies & retrospectives should prepare the team for better future planning!

Sunday, 11 March 2012

A moment of (and for) thought!


A moment of paralysis is when although you know what you are and that which you think is known to you (due to its familiarity from past thinking) you can't act upon it or execute it because the very source of the thought (the brain) does not allow your body to. A frozen moment or state of inactivity that allows only one part of your anatomy, the brain itself, to be in an active state...conclusively or consequently, the next stage of inactivity must be death! Lol:)