Saturday, May 10, 2014

Is Karma sexy?




During the last week I had to work with a JavaScript unit test execution tool. At the beginning it was bit difficult since I’m not the guy who has a crush with web based technologies. Guess what I was falling in love with this after a while. So here I’m writing a post on “karma”, another product of Google’s AngularJS team.
Testing a Java or .Net code is not a strange thing, but testing a code that written in JavaScript may be quite tedious due to its’ workflow. Again writing an easily testable code in JavaScript comes with the experience. Test Driven Development can solve these two scenarios with its prerequisites; writing a testable code and providing an effective test environment.   
The philosophy of AngularJS is quite similar with above scenarios I have mentioned, but still it requires a tool that takes the responsibility of testing your code. This is what Karma does for you. It executes test cases on your code and test them in each browser you want.
Testing your code in every browser by opening them is not what developers want to do. Karma does it automatically. You only have to mention what browsers it should be tested in the configurations.

 
                        browsers: ['Chrome']                                             

In TDD, developers have to test code in every unit they code, but this won’t happen with web development due to its workflow. Ultimately it will remain a set of bugs in the code where you have no idea of the root cause. What Karma does is, it executes all test cases when developer save an update in his code.

Karma uses node.js so there are no OS limits. It allows you to write test cases in Behavior Driven Style and wrap BDD test frameworks like Jasmine.
So finally this test runner is all about giving feedback to the developer about what he coded. This feedback is what makes developers more productive. Ultimately this provides you a productive test environment, which requires minimum number of configuration to make your life easy.

Related links: