Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #16514

Re: Unit test framework recommendations?

Message-ID <1935017.YUQ9Xjkia0@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2012-10-09 21:19 +0200
Subject Re: Unit test framework recommendations?
Newsgroups comp.lang.javascript
References <T7mdnSwpceeWQe7NnZ2dnUVZ_qKdnZ2d@earthlink.com>
Followup-To comp.lang.javascript

Followups directed to: comp.lang.javascript

Show all headers | View raw


Patricia Shanahan wrote:

> Does the group have a recommendation for a unit test framework for
> JavaScript?
> 
> I am extremely familiar with JUnit, and note that JsUnit is based on it,
> but I'm concerned that it may not be very actively maintained.

It is not, indeed.  I have stopped using JsUnit (after I had to fix some 
invalid markup in the latest 2.1 beta – always a bad sign in a Web 
application) when it stopped working in newer browsers because of security 
issues.  So I can safely and strongly recommend against using it anymore.

> Also, porting something designed for one language for use with another,
> very different, language does not always get the best results. If there is
> a better tool for JavaScript I would be happy to learn it.

I have found jasmine too intuitive (very un-JUnit-like, which its creators 
present as a virtue; but I had come to appreciate the clear structure of 
JUnit tests as well, whereas Jasmine appears to me as sort of a childish, 
jQuery-like way of writing unit test by comparison).

So I have written my own script for unit tests; I am not sure if it can be 
called a framework.  You can find it at 

<http://PointedEars.de/websvn/filedetails.php?repname=JSX&path=%2Ftrunk%2Ftest%2Ftest.js>

(which for unknown reasons is not syntax-highlighted at the moment like the 
other code in the repository).  See corresponding entries in the changelog 
<http://Pointedears.de/websvn/log.php?repname=JSX&path=%2Ftrunk%2Ftest%2F&isdir=1&> 
for more.

JSX:test.js is (IMHO) JUnit-like in structure, but because I would not want 
to go down the road of object iteration and looking for and requiring 
`test*' methods, you would define your tests as functions in an Array or in 
Objects referred to from an Array.  Test results are written to the error 
console or, if the document tree had been loaded, appended to the test 
document, or as a last resort, can be displayed with window.alert().

Although I have not designed test.js to work on mobile devices, I have found 
test.js to run in browsers on my HTC Sensation (Android) and iPhone 3G just 
as well.

One thing that test.js is not capable of is combining several unit tests.  
But maybe because testing in isolation is the very point of unit tests (as 
opposed to integration tests), it might never get that capability later.
(I have not found a need for that yet when testing my code.)

You can find an example of a real unit test using test.js, that should be 
self-explaining, at

<http://PointedEars.de/scripts/test/regexp>

Please let me know what you think of test.js and of any ideas you might have 
to improve it.


PointedEars
-- 
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Unit test framework recommendations? Patricia Shanahan <pats@acm.org> - 2012-10-09 09:10 +0100
  Re: Unit test framework recommendations? Scott Sauyet <scott.sauyet@gmail.com> - 2012-10-09 10:40 -0700
  Re: Unit test framework recommendations? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-09 21:19 +0200
    Re: Unit test framework recommendations? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-09 21:50 +0200
    Re: Unit test framework recommendations? Scott Sauyet <scott.sauyet@gmail.com> - 2012-10-10 07:24 -0700
      Re: Unit test framework recommendations? Patricia Shanahan <pats@acm.org> - 2012-10-10 22:14 +0100
        Re: Unit test framework recommendations? Scott Sauyet <scott.sauyet@gmail.com> - 2012-10-11 06:19 -0700
      Re: Unit test framework recommendations? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-14 00:11 +0200
        Re: Unit test framework recommendations? Patricia Shanahan <pats@acm.org> - 2012-10-13 23:49 +0100
        Re: Unit test framework recommendations? Scott Sauyet <scott.sauyet@gmail.com> - 2012-10-14 13:17 -0700

csiph-web