Showing posts with label google. Show all posts
Showing posts with label google. Show all posts

2012-02-06

Unit testing Google Closure applications from the command line

I've been playing around with building an application using Google Closure. I tried searching for a good way to run the unit tests from the command line as part of an Ant build, but either there wasn't anything out there to do what I wanted to do or I just couldn't find it.
As an aside, naming a language after a programming construct is really dumb. If you try searching for blog posts on Google Closure, you get a bunch of stuff about javascript and closures since they're such an important language concept. I think Prototype might have been a more successful language if they hadn't named themselves after a language construct as well, though the framework itself has its issues.
I'm used to writing code using test driven development, which doesn't work particularly well writing some Javascript. DOM-related code in particular is difficult to write with TDD. But there are parts of Javascript applications that can and should be well unit tested. When coding in PHP or Python, I normally have two terminal windows open for my Vim sessions and one for my build and source code management activities. I'll typically save the file I'm working on and them immediately alt-tab to the build window and hit up then enter to run my unit test target. I really wanted to do that with Javascript.

At my job we use jQuery. This comes with Qunit which is easy to run automagically with PhantomJS. But Qunit didn't look like it would be easy to make work with Closure in that it wouldn't handle the dependencies for me. And I might as well use the unit test framework for the library that I'm working with. I had a few goals. I didn't want my Javascript tests to fire up a browser. That kind of thing should be handled by Selenium. I wanted to be able to add new tests without having to manually add the test name to any file. I wanted the output to be at least somewhat pretty and clean, particularly if there were no failures. As a PHP developer I'm used to the PHPUnit output:


I decided to try to code up my own test runner to make this work. Here's the first version:


First, the build target concatenates all of the test files. In my case, test files are in a directory called tests and each of them ends with Test.js.

Next, it fires up the Closure Compiler. In this example, we've got a Javascript file called foo.js. We compile that with the concatenated test file (tests-concat.js) and the test runner (we'll get to that soon). The compiler creates a file called tests.js. We run that with phantomjs. The build will look something like this:


Most of the magic happens in testRunner.js:

Basically how it works is to override some methods in goog.testing.TestCase to capture the results. We don't particularly care about successes, so they're replaced by dots. Failures show as an F and any errors are explained in more detail after all tests finish.

I've uploaded all of the example code to Github at https://github.com/omnicolor/Closure-CLI-test-runner.

2010-02-11

Some thoughts on Google Buzz

Having played around with Google Buzz for a day now, I've got some random thougts. For those of you that don't know what Buzz is, it's basically a mix of the different Google social ingredients put into Gmail's wrapping. Like a Google multi-layered taco. It takes the social aspects that Google Reader has been doing well, and the comments from there and YouTube, and tries to amp them up with Gmail's interface. What this means for most of us is that we'll be able to share videos, thoughts, updates, pictures, and whatever else in our Google profiles. Then our friends can join in conversations about whatever we posted.

Like Facebook.

But there are some differences that get me pretty excited about this:
  • It's Google. Having been on the inside and having drank the Kool Aid, that alone is close to enough to get me to switch. This means very little (if any) downtime. Facebook has pretty good uptime. Twitter, not so much. Google (or Gmail for that matter) going down is newsworthy and relatively rare. However, this does pose a problem, since when Gmail goes down I usually find myself killing time on Facebook, so mixing the two might cause me to go outside if the combination dies.
  • It's really well integrated with things I already use. I use Twitter, Reader, and Gmail. My friends and I are already used to commenting on each other's stories posted in Reader. We're already used to chatting and emailing each other in Gmail. We're used to updating each other with Twitter. Few of my friends use Picasa, but I find the interface way better than Facebook's for sharing photos. Yeah, Flickr is probably better still, but I don't do it often enough to care.
  • It's more open. Facebook is easy to get data into, but difficult to pull it back out of. Google makes it easy both ways. With Googlers constantly trying to free user data (http://www.dataliberation.org/) the trend is for more things to be usable for outside apps. And that's a good thing. That means that we're more likely to see cool mashups.

There are also some points that make me wonder:
  • We've all spent a huge amount of time refining our Facebook profiles. Now we need to do the same thing with our Google Profiles. But Facebook already has a huge amount of inertia. Lots of people won't switch. So you have a few bad choices: switch and say goodbye to your Facebook-only friends, maintain both profiles and spend twice as much time and deal with the overlap of things showing up on both, or ignore Buzz completely and possibly lose touch with people that switch completely.
  • The integration, while relatively slick, isn't as seemless as I want. Why can't my Gmail inbox be the gateway to everything that I use? It's obvious that the infrastructure can handle reading long posts and commenting on things, so why can't I have my RSS items there? Why can't I have my email and buzz items mixed together? I normally use a search for "is:unread OR in:inbox". This lets me see anything I haven't read. Things that are addressed directly to me stay in my list until I have handled and archived them. Adding "OR in:buzz" shows me the archived Buzz conversations, but not the unread new Buzzes. If there is a way to see those Buzzes in my feed, I haven't figured it out.
  • If Buzz can be mashed into Gmail, why not Wave? I understand that the two products are completely different. I just don't care. Googlers are some of the smartest people on the planet, figure it out.

Overall, I'm pretty happy with it so far. But I want more.