Friday, October 2, 2009

Testing Javascript UI

This has been something I've been thinking a long time about. The key about testing javascript, anything in general in fact, is designing your code so it's highly modular, so you can test small, single-purpose components by themselves, and then combine them to test system-wide functionality. Mocks are great in this respect - if your components need another object, mocks can provide that object with no implementation, rather, just give you the methods and properties you need to test the cases you want to test.

The wrinkle that comes in testing javascript versus "easy" test subjects like Java or other non-ui languages is the fact that Javascript's nature is so intertwined w/ UI. So, a lot of times what you're testing is not as much the javascript code, as the resultant DOM that the javascript code manipulates in the function that you call. This can become quite a hard thing to test - and you need to really ensure that your checking of the DOM is correct - which may require further testing.

I think the solution to above is prototypes - I have dealt with these before, as that's how at my last job we implemented most of the portlet and other advanced functionality in the product - through the use of blank, generic blocks of DOM that we clone, manipulate and inject into the page DOM. These prototypes are IDed - thus can only appear once on the page. The key is to get the right prototype, clone it, change it as we needed it, and inject it into the DOM - thereby "creating on the fly" a new and unique DOM element.

Adapting this technique to testing: create a number of raw prototypes - these should be the SAME prototypes you're currently using in your code. To ensure you're using the same prototypes, you might want to actually have a build-time step to join a single-set of prototypes to both the app pages as well as tests (which implies that tests should ALWAYS run during build).

So, using these prototypes, you would create a set of DOM elements, which will be the END RESULT, as you have designed your DOM to be, of what will happen once these prototypes go through the code and be injected into the page's DOM.

Coming back to the javascript portion of javascript testing, ideally, your methods are small and change only certain parts of the DOM. With the "resultant prototypes" produced from previous step, you can compare them using a simple recursive tree routine with those DOM elements produced by your javascript - simply go down attribs and elements, to see that they match. If these match, you're all set, if not, well, you've got work to do :)

This has a several positive effects - first, your code will have unit tests - something that most javascript doesn't - which is unacceptable. Secondly, your code will be that much more regression proof - especially as libraries get re-used (which they will more, if they are more granular). Third, and perhaps more important, you will do your design upfront, and have a great idea about not only what your code will look like, but will also have an opportunity to optimize your DOM before writing any code - thereby making your code more compact and efficient.

Check out the following links:

Friday, May 8, 2009

In response to article about India's informal economy

Original article here: India's Informal Economy and the Global Recession

Semil, it's a very interesting perspective on India, but I think it's a bit too optimistic. While the younger Indians are certainly hungry for the western idea of success, the older generations - the Sonya Gandhis and LK Advanis are running the massive, inefficient bureaucracy which, at the end of the day, is responsible for fiscal decisions in the country.

Moreover, this new middle class is seemingly uninterested in changing the status quo - just look at youth voter turnout in current and past elections. While they may be hungry, they seem somewhat complacent as well. And while more Indians are receiving access to better education, it's decent at the higher level, but isn't very good at lower, public, schools - all due to this "informal economy." Let me elaborate.

The fact is that much of this "informal" economic activity - black market - is untaxed - and even legitimate economic activity in India is heavily under-taxed. Added to that the fact that corruption is so rife in this country, you've got perhaps India's biggest issue - lack of investment in infrastructure - both physical and social.

Sure, India has been able to heavily leverage its colonial past - a good education system and a large pool of English speakers - to create this new middle class. But how long will it last? Certainly not forever. And with this informal economy choking-off legitimate government investments in infrastructure and education, India's growth is invariably going to slow ever more.

Added to above, you must consider changes in US laws for both H1B visas and outsourcing of jobs, and the fact that remittance from US to India makes up over 3% of the Indian GDP - more than two times the annual spending on education and health care by the federal government - and contributes to this informal economic activity - and the picture looks much more bleak than before.

Monday, February 16, 2009

Update from India

I am in India now, arrived two weeks ago. Working w/ our outsourcing team at FIS Chandigarh - which is in northern India, between, and capitol of, the Haryana and Punjab states. So far, it's been very interesting discovering what the team is all about and the city as well, and I think I am going to get a ton of really great experience leading so many developers working here for 6 months.

The initial week was \a bit tough - I've been challenging these guys regarding the legacy the code - why certain decisions were made, etc, and so far everyone has been responding very positively - I am noticing an improvement in code quality, as well as the final output - and it shows - so far our work is looking like it will produce significant improvements in performance and reliability.

So, for the next release, we're doing major surgery to Compensation spreadsheet. We're doing code cleanup and consolidation for this release (7.1.6). After we get a baseline of all used templates and functions in the code base, we're going to dive in and actually clean up the code - rewrite parts of it as jquery plugins - so it remains looking like it does, but works significantly better and faster.

Other than work, Tushar helped me find a cool apartment in the city - 3 bedrooms, 2 bath - which is only 3.5 km (about 2 miles) from work. I also picked up a sweet folding bike (I like to have a mode of transportation when I am traveling, and bike is my preferred mode :). I have been able to ride a bit around the city - drivers here are CRAZY. Everyone honks at each other - not as a sign of disrespect, as one would expect, rather, as a notice of one's presence - as in, "hey, I am here, watch out." Makes sense, too, as no one follows traffic rules :)

Air quality here is not great - so at height of traffic, it's pretty stuffy on the roads. Nonetheless, biking isn't bad at all, and it gives me a chance to exercise and see the city.

My girlfriend is arriving this week - on Friday. She'll be here with me for 6 months. We're hoping to start a regular yoga practice, and she's hoping to study yoga to be an instructor. I'm also hoping to pick up a new skill - there is a horse-riding school here, a tennis club and a golf club. I would love to learn tennis, and gold is great too. So, if anyone has any suggestions, please DO pass them along!

Otherwise, things are pretty good. I am settling in and doing some good work. I will try to update people regularly, and promise to send a pictures link when I get some up!

Wednesday, January 21, 2009

T minus 6 days and counting!

Well, most of my room is packed away into a tiny storage locker in Berkeley and I am done with all of my business visa stuff - I am ready to go to India!

The visa process was fairly simple - an online application for all of the important info, a letter from my work that I am indeed going on their behalf and a letter from the water department that I am indeed living at my current address. After that, a fairly short line at the Visa outsourcing office and a follow-up visit the next day to pick up my new visa. No issues!

The room situation got resolved fairly simply as well - packed up all my "going to India" stuff into my huge suitcase and the rest into storage - including my beautiful bikes. I will miss them when I am abroad.

So, now, all that's left is to do another cataloging of India clothing/equipment to make sure I am not going to be lacking anything, and then off to NY on Thursday night!

It's been fairly easy getting things done for this trip. With a ticket in hand, I've not had much problems motivating myself to clean, pack or anything else of that manner. Poppy's ticket is also already purchased - and she'll be joining me mid-February.

Is there anything else I should write about?

Saturday, January 3, 2009

Paring down my life, or, It helps to only have one room

I've been somewhat upset with myself regarding the acquisition of new items after I did such a great job getting rid of stuff when I left Chicago. Sure, I didn't mind getting the new bikes - those are great - but everything else? Well, that came to head recently as I went through my wardrobe. I jettisoned nearly 20 pounds of clothing - much of it worn less than a handful of times! How wasteful.

A goodly portion of the clothing was simply too big on me. I now wear size 33 pants, but much of my "Chicago" wardrobe was size 36. Well, clearly that stuff won't be making it to the next step in my life. Then came the suits - one was over 8 years old and was big enough for two of me (I think it was size 43 reg, I wear 38 reg now)! I think it will find a great new home being given to Career Gear - an org that donates suits to men who are in job training programs. A worthy cause, and not wasteful.

I've also been sending unused and unneeded gear back to Steep and Cheap for the last few weeks. I am hoping it will result in a nice rebate from them, and I am glad to get rid of all of the awesome gear I bought but will never get to use - either because I have 4 of it (or 20 of it if you're talking about backpacks) or because it just didn't fit (alas, medium is not the same everywhere).

I am going to India!

I am going to India! It's official. I purchased my ticket today - leaving from New York on Jan 27th and arriving in Dehli on Jan 28th, 2009. I am very anxious about this trip. Not only is this a big opportunity culturally and career-wise for me - as I will describe in more detail at a later date - but it's also a great opportunity for me to pare down my life, once again, and start anew.

There is more to come, and pictures too - please bookmark this site, or subscribe to it. If you're reading this, please let me know what you'd like to read more of. I will share my adventures in South East Asia, findings about managing a development team, techniques and new-found wisdom and general impressions of India and its people. Stay tuned!

Wednesday, August 13, 2008


This is a test post from flickr, a fancy photo sharing thing.