Archive for category Uncategorized

The power of nested describes in Jasmine

I’m experimenting with the Jasmine JavaScript testing framework to see if I can create a cucumber style testing framework using JavaScript. I want to go full out TDD on it so I started with a feature file, now I’m working on a spec to get that file running.

However as I work I get stuck on the following:

image

The description is too high level!

What happens when I load the feature file? Obviously a feature is loaded, but how? Something needs to happen between loading the feature and running the steps. My test needs to be more detailed.

Why not describe the load function then?

image

At once I realized that the load function needs to be asynchronous.

,

No Comments

Job dependencies in Hudson for our Continuous Delivery effort

I’m continuing our work with our Continuous Delivery effort. Were migrating from our previous build system to Hudson since it makes builds much more accessible.

The work started with the continuous delivery with hudson project I have on github and were slowly adapting a fork of that to work with out scenarios.

We realized that the amount of builds that we will be hosting in Hudson might make it hard to get an overview of what depends on what. After some research I found out that you could add the following to the URL of your hudson to get a dependency graph of all the builds:

/dependencyGraph/graph

So if you host Hudson locally it would look like:

http://localhost:8080/dependencyGraph/graph

This is how our current dependency graphs looks like:

image

The package output build takes the result from our old package build and migrates it over to the delivery pipeline. The Template Schedule Deploy job (which I now realize is a bad name) takes a set of “job files” and run the deploy installation job with the given settings.

The Create job files based on search creates the job files that the template deploy job works with, and the upgrade early, test, and bulk installations does a search in our installation of RemoteX Applications to find out which installations to upgrade based on the units in RemoteX Applications.

Each job then run the deploy installation build (not visible in the graph) to deploy the upgrade for each customer. In essence running the same build for upgrading that we use every time we deploy anything.

,

2 Comments

Development as a team or development as stars?

A good friend and colleague of mine Johan Andersson read somewhere that you can see the communication patterns of a company in the architecture. I can see how that makes sense, but I think its much clearer than that. I think you can see the communication patterns of a company in the interface of its products. Both API’s and UI.

Every bump in the flow of a product, every view that is different from the main theme, every glitch in the feel of the application. They all show where a Star has solved a problem. They all show where communication failed and brute force problem solving stepped in to save the day.

An example could be an integration that uses a mostly unused field to store some information that it was not meant to store. Such as dates being printed in a text-field. Or having to leave the application to complete parts of the workflow on a webpage (or on a different site).

If we consider an application and its features as an onion. At the heart of every application there is a core functionality, the minimum viable product. On this other features evolve, or are developed. In essence making it a bigger onion for every aspect covered.

It could look something like this:

Teamwork feature circle Stars feature cicle
Teamwork feature circle Star work feature circle

Now let each layer be complete, if the workflow of the feature is complete. A layer is incomplete i.e. graphed, if they break the flow of the product in order to solve a problem. If they just add enough functionality so it solves the task at hand.

Naturally these describe the wholeness of the experience, and is not tied to the implementation in any other way other than the feeling one gets when using the product. A product developed with good teamwork feels whole and complete around each feature. A product developed with individual stars will still solve the task at hand, but the experience of using it is scattered and lacks flow.

Is this bad?

Pros

  • The problem was solved
  • Functionality is implemented as the customers wish
  • A sale was hopefully made, money was gained
  • It might have gone faster due to reduced communication costs

Cons

  • There is a glitch in the workflow of the application
  • Something looks astray if you consider the whole
  • There is a severe risk of bugs being introduced at a later stage, due to things not working as expected
  • It might cause rework to repair the flow, or fix the later introduced errors

These lists are probably longer, but they show the pattern

Let’s look at this from a sales perspective. If your method of selling is by listing features and selling a complete system, the stars approach is desirable, it will give you a list of features quickly. At the risk of the development going slower further down the road, especially if you build on “previous” features.

If you, however, sell by demos or free trials, showing the experience of the product and how convenient it is while solving the problem. Working with previous customers who testify to the product’s stability and trustworthiness. The teamwork approach will most likely give you the best experience, and reduced amount of bugs. Thus it might go faster in the long run.

From a buyers perspective, I’d rather use a product with complete flows.

Now ask yourself, are you a star or are you a team member?

How does your organization sell its products? Does selling like that benefit Star development or Team development?

What benefits your organization most? Teamwork or stars?

, ,

No Comments

What if I worked with a story to being with?

I’ve been working on a pet project, just to see if my idea was possible at all. Central to the idea was sharing of content between users, and I wanted to see if I could build a model to make it work on Google AppEngine.

Now I started out with some spec-style unit tests to make sure that it was feasible. Then when I started to see some progress started to bone out a walking skeleton for the application, a thin red line.

However somewhere along they way I drifted off testing the primary entity of the application and instead the focus was around one of its neighboring entities. The reason was that the other entity is central to controlling the sharing but its not the entity shared. Once my walking skeleton was complete I noticed that I had indeed created a model that solved the wrong problem.

Now all was not lost, I changed the tests that had drifted off in the wrong direction and a few hours of intense thought later I had conceived a model that solved to correct problem. I had my spec-style unit tests in python covering my refactoring and most of the skeleton still worked after I refactored.

To rethink my model I went back and wrote down what I wanted to achieve in a story format. The tests I rewrote became more like Given When Then than the spec style that was a result of the initial unit-testing.

So now I can’t help but wonder, what if I had had a cucumber acceptance test to begin with?

I’d be forced to consider what I wanted to solve on the correct level of abstraction, and I might not have drifted away from the original idea.

,

No Comments

Running tests as files change

I mentioned earlier a solution where Eclipse would run all my Python tests when I save a file. This is very convenient when using TDD in languages that can run tests fast. However that solution is tied to Eclipse and as I like Vim more and more I stand without an option to automatically run the tests as I code.

This feature is quite similar to AutoSpec in Ruby. So I figured there would be some solutions available for Python already. Looking around I found this to be the best possible solution right now. However that solution doesn’t handle nose tests, and the project I’m working on is using nose-gae to do the testing. So I needed a solution that worked on Windows and could run nose tests with nose-gae.

This started to annoy me, especially since it would be quite easy to implement it in .Net and have it work with the command-line to add support for any type of action that needs to be run on a file change.

So I wrote a little tool, which I call: OnChange

It’s a command-line application that watches the current directory and any directory under it for file changes. When a change occurs it will file a specified program, in my case, run my tests.

It also has support for parsing the output of the command to run, so with regex patterns you can add “reactions” to how the executed program is run. This allows me to signal Growl for Windows to bubble up “tests fail” or “tests pass”.

I also added a filter option so it will only react to changes in certain files.

This is how I set up my onchange program to run tests and signal pass or test automatically.

onchange -f *.py -r "^FAILED.*$:fail.bat" -r ^OK.*:pass.bat runtests.bat

This command line will cause OnChange to watch for changes to *.py files (-f flag). It has two reactions set up on that matches on FAILED test output and in that case runs the fail.bat command, and on that matches the OK test output and in that case runs the pass.bat command. The last argument to the call is my runtests.bat file. The runtests.bat file will execute the nose tests, and in an extension also execute my Jasmine tests in the same project.

The source for OnChange is available on GitHub. Feel free to help add to it if you’d like.

,

No Comments

Adding elements to mustache.js templates

I’ve been experimenting with Mustache.js to do templating for a JavaScript project of mine. One thing that I’m having trouble with is that there’s no way to add more dynamic elements to the resulting template. The output is an HTML string.

What I want to do is to insert HTMLElements into a layout I created using Mustache.js.

Being inspired by the Mustache.js partials I came up with this function to run after I’ve constructed my template:

    var to_elements = function(html, elements) {
        var result = $(html)[0];
        for(element in elements) {
            $("#"+element, result).replaceWith(elements[element]);
        }
        return result;
    };

It will run and replace all elements with an id that matches a the members of the object I provided. Here’s an example usage:

        var layout = to_elements("<div><div id='projectform'></div><div id='projectlist'></div></div>",
            {
                projectform : createProject.element,
                projectlist : projectList.element,
            });

This will produce the following output:

<div>
  <div class="form">
    <input type="text"><button>+</button>
  </div>
  <div class="list">
    <div>aaaa</div>
    <div>test</div>
  </div>
</div>

This output however is in the form of HTMLElements where I’ve attached all events and handling, allowing me to test the individual parts of the individually using templates to coordinate everything together at the end.

2 Comments

A new version of Windows Live Writer

I’m probably the last in the world to notice that there is a new version of Windows Live Writer available. It doesn’t upgrade it self when you ask the old version to check for updates. I found it purely by accident.

Once I downloaded it from here: http://explore.live.com/windows-live-writer?os=other

It upgraded the installed version of Live Writer, all my settings seem intact.

The new interface has a ribbon at the top instead of a toolbar. This might take some getting used to since I don’t particularly like it. Then again, I can hide it so I guess that’s an improvement.

,

No Comments

Book Review: JavaScript the Good parts

javascript_coverMarkus Andersson recently recommended a book to me called JavaScript the Good parts, by Douglas Crockford. As we were discussing inheritance around JavaScript it came up, so to demonstrate to power of my Kindle I purchased it so we could check out the specific example we were discussing.

JavaScript the Good parts is quite different from other language specific books I’ve read. It’s short and to the point, a feature not commonly found around American authors. It is however also opinionated, not everyone might agree with it’s content. Which is great because it means you have to think about the content.

What I really liked about it was how it described the different ways to arrange and encapsulate your JavaScript functionality. It also provides a heads up for a few more common mistakes.

The chapters on Regular Expressions, there is two of them if I remember correctly. One discussing the good and bad parts of Regular Expressions in JavaScript and then a reference chapter.

The book is suited both for people whom are new to JavaScript and to people who’ve worked with it before. But then again it is focused on the language primarily, so more senior JavaScript developers might focus more on different styles of JavaScript implementations.

,

No Comments

Introducing Tool tax

tax-attorney-los-angeles[1] I’ve been trying out a few different “tools” just too see what tooling looks like in different environments. There are several different tools solving the same problem in their own more or less unique way. They also take different amounts of time to solve the problem.

The time it takes to use a tool is a tax on the developers time. For example, there is a difference between doing a check-in in a source-control system when it takes 2 seconds compared to 0,2 seconds.

In money these figures are too small to measure: with an estimate of 10 check-ins per day you get 100 seconds per week compared to 10 seconds. It is a minor amount of time to optimize around when looking at the whole development process, but it matters much for the work environment. Switching to faster development tools can increase productivity not only due to the time saved when using them, but also due to reduced amount of content-switching.

notunderstand[1]I joined a session at DynCon 2011 where we did wolf pack programming. It was very interesting because it introduced an environment where there was no tool tax while developing. The IDE automatically updates and shares the code as soon as it can compile what you just typed in the IDE. Since Smalltalk can hot swap code the immediately updated the running production code. In essence there were no cost for committing, compiling, running builds, deploying and what not.

It turns out that behavior change. Collaboration becomes much more important as the system has zero cost for developing in a shared environment. After a few hours of wolf pack programming, the team was discussing lively and producing code collaboratively in a way that I’ve rarely experienced in real environments.

No Comments

Working with Jasmine

I’ve been working extensively with JavaScript these past weeks. As I mentioned earlier I wanted to try out Jasmine and I definitively got the chance. I’ve been using it for all my testing needs these last weeks, and I love it.

What do I like about Jasmine?

  • The ability to nest describe statements
  • the splitting of specifications into several files
  • the output structure

What I do not like

  • At times failing tests can give cryptic error messages in Chrome, since Jasmine will trap the errors inside it’s own execution. This can cause the stack trace and the error messages to mess up.

Let’s see some examples then:

describe("A view holder", function() {
  describe("when adding a view", function() {
    it("it should add the view's element to the holding div", function() {
      loadFixtures("/specifications/spec/holder.html");
      var holderDiv = document.getElementById("holder");
      var docHolder = new ViewHolder(holderDiv);
      var template = "<div>test</div>";
      var doc = new View({template:template});
      docHolder.showView(doc);

      expect(holderDiv.innerHTML).toContain(template);
    });
  describe("when removing a view", function() {
    it("the previous view is displayed", function() {

        var docHolder = new ViewHolder();
        loadFixtures("/specifications/spec/holder.html");
        var holderDiv = document.getElementById("holder");
        var docHolder = new ViewHolder(holderDiv);
        var template = "<div>test</div>";
        var doc = new View({template:template});
        var doc2 = new View({template:template});
        docHolder.showView(doc2);
        docHolder.showView(doc);
        docHolder.popView();
        expect(doc2.element.style.display).toNotEqual('none');

    });
  });
});

This is an example of a specification I wrote for a view system I’ve developed, the output looks like this:

image

I added the following snippets to SnipMate so now I have a really nice flow when writing my specifications:

# Describe
snippet desc
  describe("${1:description}", function() {
    ${2}
  });
# it
snippet it
  it("${1:does}", function() {
    ${2}
  });

Jasmine is now my testing framework of choice for JavaScript testing.

,

No Comments