Sunday, August 29, 2010

Test Drive Hello World

Earlier this week during a discussion on Test Driven Development TDD I commented to an associate that "once the TDD mindset takes a hold of you, you will find yourself writing the test before you write a single line of code even for something as trivial as hello world." My friend paused and asked how and I responded, well I would write a test to look at Standard Output and assert that it contained 'hello world'. The test will fail, then I would write to the Standard Output and watch the test failed. We moved on to other topics but in the back of my head a voice said 'why not try it out'

Here is chronology of that trial:
I first wrote the following unit test to capture Standard Output

[TestMethod]
public void TestSayHello()
{
string logFile = "test_log.txt";
string result;
using (StreamWriter writer = new StreamWriter(logFile))
{
Console.SetOut(writer);
SayHello();
}

using (StreamReader reader = new StreamReader(logFile))
{
result = reader.ReadLine();
}

Assert.AreEqual("Hello World", result);

}

Next I wrot the following method to get my unit test to pass

private void SayHello()
{
Console.WriteLine("Hello World");
}

I next DRYed the unit test by introducing the following helper method

private string CaptureStandardOutput(Action perfromAction)
{
string logFile = "test_log.txt";
string result;
using (StreamWriter writer = new StreamWriter(logFile))
{
Console.SetOut(writer);
perfromAction();
}

using (StreamReader reader = new StreamReader(logFile))
{
result = reader.ReadToEnd();
}
return result;
}

Which in turn cleaned up the unit test as follows

[TestMethod]
public void TestSayHello()
{
string result = CaptureStandardOutput(SayHello);
Assert.AreEqual("Hello World\r\n", result);
}

Sunday, August 8, 2010

Land The Tech Job You Love by Andy Lester

Land The Tech Job You Love by Andy Lester is a must read for everyone. Even though the title suggest that it is targeted for the techies, this book contains valuable insight and advice for the non-technical among us as well.

Andy walks the user from preliminary steps such as determining what you want in your next job to the offer letter and beyond. Early on in the book Andy gets the reader to reflect on vital questions such as what do I want in the a job and what are the factors which are key
motivators in this stage of my life.

Next, he provides excellent advice on the content and structure of your resume. He covers the all important question of what format should the resume follow and gives key pointers on what should and should not be included in this all important document.

The importance of personal network in finding a job is covered next and he provides interesting statistics regarding the effectiveness of various mediums such as job boards, company websites, head hunters and referrals. Next, he covers applying for the jobs and how you should tailor
your resume and your cover letter for that particular job.

Important advice for the preparation and execution of the job interview is covered next. He devotes an entire chapter on handling tough interview questions and another on which questions to avoid during the interview. Next, he gives advice on how to handle things after the
interview such as thank you notes, followup inquiries, references, and the all important job offer.

The final chapter gives great advice on keeping yourself marketable. This has prompted me to resume blogging. He echos many of the sentiments found in some of the other books in the pragmatic bookshelf series such as, improve yourself, improve your network, and improve your brand.