Contents

Before going into how to setup Jasmine to do Unit Test for ExtJS, I think I should describe why I am doing this.

I have been using ExtJS for around 4 years. My first company used HTML + ExtJS to build the UI while the current one use ExtJS completely to do that. I have encountered lots of cases that well-tested behavior failed after some new features introduced in.

Everyone knows that it’s because there lacks Unit Test. However, there have never been any Unit Test done for Javascript in any project. There are many of the reasons behind that, such as tight schedule, not enough attention etc. But the most important reason that outweights or strengthens others is that Unit Test for Javascript is way too difficult than Java, especially when Javascript is used intensively to build the UI and implement business logics.

One of the reason makes Javascript hard to do Unit Test is due to good tools unavailability; the other one is that most developers tend to not separating business logic from UI code quite clearly.

After the emergence of Selenium, I have once thought it should be the right tool to address this issue. However, after reading Selenium Doc and seeing what my previous colleagues did for recording & playing, I think Selenium should be used mainly for Integration Test, not in Unit Test level. My opinion is further strenghten after watching a video from Google Testing Expert and reading the blog from Martin Fowler:

让测试也敏捷起来 by 段念

TestPyramid by Martin Fowler

The main points in TestPyramid are:

  1. Low-level unit test should be many more than high level end-to-end testing through GUI.
  1. Testing through UI is slow, brittle, expensive to write.
  1. A rich javascript UI should have most of its UI behavior tested with javascript unit tests using something like Jasmine.

Above is a long long purpose briefing, I hope it worthes to let you know the background and also agree with me on this. I heard about Jasmine before reading the post by Martin Fowler, however, I kept thinking that it’s quite difficult or even impossible to use Jasmine to test those ExtJS UI components.

Until I did sit down and really tried to use Jasmine to test the ExtJS code, I can say that Unit Test against ExtJS by Jasmine can be achieved at some level once we know what to test for.

In next post, I will show you the steps to bind ExtJS, Jasmine, Maven together to do the Unit Test and what I think we should test against.

Contents