So I haven’t worked on my WatiN Mac os x port for a few days, but I got back into it last night. The main hurdle at the moment is that the System.Diagnostics.Process class is not fully baked on Mono 2.4 on the Mac platform, because it doesn’t implement the /proc filesystem that linux does.

The correct thing to do would be to learn how the Mach kernel process structure works and fix mono, but I haven’t programmed in non managed C since 1990 and I would be very dangerous, especially at such a low level in mono.

So the first approach was to use the parts of mono that were working, namley Proces.Start() to call a shell script that I wrote to /tmp, then redirect standard out to a file, then parse that file and act accordingly.

StreamWriter sw = new StreamWriter("/tmp/watin-listprocess.sh",false);
sw.WriteLine (@"ps x | grep" + processname + " | grep -v grep > /tmp/watin-processlist.out");
sw.Flush();
sw.Close();

Process shScriptProcess = new Process();
shScriptProcess.StartInfo = new ProcessStartInfo("/bin/sh","/tmp/watin-listprocesses.sh");
shScriptProcess.Start();

A hack, yes, in fact a very messy hack. So messy there had to be a better way.

And there is …

Enter Monobjc. Monobjc is a managed wrapper around the Mac os x Cocoa API’s. A quick search pointed to the NSTask and NSPipe classes as a way to start a process with NSTask, and capture standard out with NSPipe, then parse the result.

A much more technically correct solution.

public static void Main(string[] args)
{
// spin up the objective-c runtime
ObjectiveCRuntime.LoadFramework("Cocoa");
ObjectiveCRuntime.Initialize();
NSAutoreleasePool pool = new NSAutoreleasePool();

// Create our process
NSTask task = new NSTask();
NSPipe standardOut = new NSPipe();
task.StandardOutput = standardOut;
task.LaunchPath = @"/bin/ps";

// add some arguments
NSString argumentString = new NSString("-ax");
NSArray arguments = NSArray.ArrayWithObject(argumentString);
task.Arguments = arguments;

// We have liftoff
task.Launch();

// Parse the output and display it to the console
NSData output = standardOut.FileHandleForReading.ReadDataToEndOfFile;
NSString outString = new NSString(output,NSStringEncoding.NSUTF8StringEncoding);
Console.WriteLine(outString);

// Dipose our objects, gotta love reference counting
pool.Release();
}

So this needs to be fully baked in and then put into my Watin on mac os x port and then it should work stand alone, without shell script assistance.

I didn’t think it would be this easy, but it’s working. I can now run a basic WatiN test on mac os x using mono.

The code is here http://code.google.com/p/mcwatin/. All credit to the WatiN guys, all I did was remove stuff :-)
Here’s what you need to get this running

Mono 2.4 and MonoDevelop preview for mac os x from here
The source code from http://code.google.com/p/mcwatin/
Firefox 3 with JSSH installed.

start firefox up with the following command line

/Applications/Firefox.app/Contents/MacOS/firefox -jssh

Then run the test. It will work but fail as exceptions are being thrown in the dispose method.

1. Get a subset of WatiN to compile with no PInvokes done

2. Get McWatiN to successfully start firefox. done

3. get McWatiN to run a basic test. done

4. Replace all the windows and IE stuff that was removed with code from Watir.

Building: McWatiN (Debug)

Building Solution McWatiN

Building: McWatiN (Debug)
Performing main compilation...

Build complete -- 0 errors, 0 warnings

---------------------- Done ----------------------

Build successful.

Two words that mean so much … this time they refer to WatiN built using MonoDevelop on Mac OS X.

1. Get a subset of WatiN to compile with no PInvokes done

2. Get McWatiN to successfully start firefox.

2. Replace all the windows and IE stuff that was removed with code from Watir.

My presentation at the Microsoft SDC open day alongside Devtest CEO Sarah Richey is now up on Microsoft’s site.

MePresentingAtMicrosoft.jpg

http://www.microsoft.com/australia/services/microsoftservices/sdc_openday.mspx

For my presentation you need to open the “How we do: Testing” video and I am in the last half following Sarah.

I am currently thinking about developing and delivering a WatiN training course. Is this something that anyone would be interested in ? If so, drop me a line via the comments on this blog.

Next Monday will be interesting, as I am presenting at the SDC Open day alongside Devtest CEO, Sarah Richey.

Here’s the blurb from the Microsoft site.

In challenging economic times, software development projects that are critical enablers to achieving business goals, will be looked at favorably and expected to deliver the results with a high degree of certainty. At the SDC open day, Microsoft’s own software development arm the Solutions Development Center (SDC) will present and share with you its formula to achieving certainty and success in project delivery.

You will hear from the SDC project teams on how they apply agile planning and development processes to deliver the right solution. How metrics-driven project management is used to keep the project on track. How daily builds and deployments help to maintain the project “heart-beat”, and how the SDC incorporates unit testing and automated testing into the process to ensure ongoing quality. .

You will also learn how Microsoft development tools and technologies are put to use throughout the software development lifecycle to enhance individual and team productivity.

Finally, you’ll have the opportunity to step inside the SDC facility and learn how the workspace is used to promote innovation, team collaboration and knowledge sharing.

I only have 10 minutes so it will be a “short and sweet” session, and attendance has closed, but there will be ~130 people in attendance.

This is just brilliant … check out this ad for Microsoft Office for mac.

Generally there are two key factors at play here: requirement delivery and bug fix rates.

The simple way

The simple answer is to average the number of bugs fixed per day, and divide the total number of bugs by the average. That is approximately how many days until you reach zero bugs. So, if you are fixing 5 bugs per day and you have 200 active bugs, the earliest that you will ship is in 40 working days time. If you want to ship sooner, you will need to stop adding features and focus on fixing more bugs.

The same information can be used in reverse to calculate a maximum allowable bug count. Say you only have 40 days until your desired ship date, and you are fixing 5 bugs per day as in the previous example. If you active bug count is over 200 today, you will probably miss your target. This number continuously decreases so in 2 weeks time, with 30 working days to go, your bug count should be at the 150 mark if you are going to hit your ship date.

The advanced way

In the 1950’s there was a little project that was underway at the Los Alamos National Laboratory in New Mexico. The manhattan project, required some advanced simulations, and they named the method they used after the Monte Carlo casino, which can be found at Turn 4 of the modern Monaco Formula 1 Circuit. There are essentially 4 steps to performing a Monte Carlo simulation:

1. Define the inputs in to the problem.
2. Randomly generate inputs for your problem.
3. Apply the random values you generated to your problem.
4. Repeat step 3, enough times to get statistically valid results, and then combine and analyse them.

Applying this method to our problem the steps become the following, assuming a data set where the bugs fixed - bugs found for a 2 weeks period results in the following data : 2,3,1,4,0,2,2,1,2,3

1. Determine the average and standard deviation of bugs being fixed over time. For our example the average is 2 and the standard deviation is 3.16.

2. Using Microsoft Excel, use the following function to generate valid random data =NORMINV(RAND(),Average,StandardDeviation).

3. In an Excel worksheet use the values that you generated in step 1, to workout the number of days to ship, I used an IF function and then COUNTIF to count if the days to ship was greater than zero.

4. In excel, copy the above 100 times and then plot the results.

ESDRawPlot.gif
ESDShippingChance.gif

The first chart is the scatter plot of the simulations. The second one shows the standard deviation of the estimated ship dates, and shows the chance of shipping in X number of days in the future.

The interesting thing about this model, is that even for 20 defects, and an average of fixing 2 per day the minimum days to ship is 3, but the maximum is 37 !

So back in 1994 Denso Wave invented the QR codes. In 2008, Microsoft launches Microsoft Tag, their version of exactly the same thing.

Do we really need two competing standards for exactly the same thing. As consumers here we go again, it’s VHS vs. Beta, DVD-R vs. DVD+R and Blueray vs HD-DVD, and ethernet vs. token ring all over again.

Sigh.

I saw this today whilst analysing automation failures, and it made me laugh.

Assert.AreEqual failed. Expected:<10904.73>, Actual:<10904.73>.

So this is what happens when you compare two different types of double precision numbers …