472,980 Members | 2,079 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,980 software developers and data experts.

Anyone use JSUNIT for unit testing?

Does anyone actively use JSUnit < http://www.edwardh.com/jsunit/ > for unit
testing their javascript code?

For logical functions, I imagine it could be very useful.

However, I'm wondering how well it would work for other things which are
browser-dependent, like DHTML. Any personal success or horror stories?

--
Matt Kruse
http://www.JavascriptToolbox.com
Jul 23 '05 #1
3 2200

"Matt Kruse" <ne********@mattkruse.com> wrote in message
news:d1*********@news4.newsguy.com...
Does anyone actively use JSUnit < http://www.edwardh.com/jsunit/ > for unit testing their javascript code?

For logical functions, I imagine it could be very useful.

However, I'm wondering how well it would work for other things which are
browser-dependent, like DHTML. Any personal success or horror stories?


In a related vein, how interesting would a JavaScript test coverage tool be?
Client side? Server side?

--
Ira D. Baxter, Ph.D., CTO 512-250-1018
Semantic Designs, Inc. www.semdesigns.com
Jul 23 '05 #2
Ira Baxter wrote:
"Matt Kruse" <ne********@mattkruse.com> wrote in message
news:d1*********@news4.newsguy.com...
Does anyone actively use JSUnit < http://www.edwardh.com/jsunit/ > for


unit
testing their javascript code?

For logical functions, I imagine it could be very useful.

However, I'm wondering how well it would work for other things which are
browser-dependent, like DHTML. Any personal success or horror stories?

In a related vein, how interesting would a JavaScript test coverage tool be?


What do you define as a "JavaScript coverage tool"?

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #3
Matt Kruse wrote:
Does anyone actively use JSUnit < http://www.edwardh.com/jsunit/ > for
unit testing their javascript code?

For logical functions, I imagine it could be very useful.

However, I'm wondering how well it would work for other things which
are browser-dependent, like DHTML. Any personal success or horror
stories?


Kupu uses ecmaunit rather than jsunit, but since they are both just xUnit
implementations the same principles apply. The degree to which unit tests
are actually implemented for Kupu has varied over time, current the trunk
has 71 tests. In particular one of the developers has recently been adding
tests for some of the harder areas to test: We have some classes which
manipulate selections in an editable iframe, so the tests have to set up a
suitable iframe, add content, select it, do the test, then clean up the
iframe. Here's a test I wrote using his _setSelection support method:

this.testSetTextStyle = function() {
var data = '<p>line 1</p><div class="Caption">line 2</div><div
class="Caption">line 3</div>';
// select .....................................|e 2</div><div
class="Caption">line|...
var expected = '<p>line 1</p><h2>line 2</h2><h2>line 3</h2>';
this.body.innerHTML = data;
this._setSelection(10, null, 18, null, 'e 2line');
this.ui.setTextStyle('h2');
this.assertEquals(this.cleanHtml(this.body.innerHT ML), expected);
}

_setSelection here is asked to select the 10th to 18th characters and
verify it has selected 'e 2line', the string being provided to act as a
double check on the counting (and when first written the selected text
didn't match on the different browsers). Then the actual test: call the
ui.setTextStyle method to set the currently selected region to a level 2
heading, then verify that the resulting HTML matches what we expect (with
appropriate cleanup to remove browser inconsistencies):

this.cleanHtml = function(s) {
s = s.toLowerCase().replace(/[\r\n]/g, "");
s = s.replace(/\>[ ]+\</g, "><");
return s;
}

Since almost all the methods which are tested are supposed to be cross
browser (or in Kupu's case cross-browser so long as your browser is in the
list of supported browsers), browser dependency is handled simply by making
sure that all tests pass on both Mozilla and IE. I usually run with a tab
or window open on the unit tests for each browser and concentrate on
developing on Mozilla but every so often check the tests still run on IE.

Occasionally there are problems with one platform but not the other: the
worst one was that I recently found that every time the tests ran on IE
they took 0.2 seconds longer than the previous time: the class
containing the test I showed above needs to set up more of the Kupu
environment than most of the tests and tearDown wasn't managing to tidy
everything well enough.

Feel free to look at the Kupu sources from
http://codespeak.net/svn/kupu/trunk/kupu, get ecmaunit from
http://codespeak.net/svn/kupu/trunk/ecmaunit. Run the javascript tests from
kupu/tests/run_tests.html. The test I quoted comes from test_plone.js and
that testcase subclasses SelectionTestCase in test_kupuhelpers.js.
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: | last post by:
Hi! I'm looking for unit-testing tools for .NET. Somthing like Java has --> http://www.junit.org regards, gicio
4
by: Peter Rilling | last post by:
Does VS.NET 2005 Professional support integrated unit testing, or is that only with the team system?
1
by: Jody | last post by:
Hi, I'm trying to get JSUnit to work - I've tried everything I can think of, but I can't get the simplest of tests working - example 1 of the jsunit homepage - Both on my server and locally,...
72
by: Jacob | last post by:
I have compiled a set og unit testing recommendations based on my own experience on the concept. Feedback and suggestions for improvements are appreciated: ...
1
by: mitch | last post by:
Does anybody know how to get JSUnit (JavaScript unit testing framework) and Venkman (Firefox JavaScript debugger) to work together?
4
by: Dat AU DUONG | last post by:
Hi, I am new to Unit testing, could you tell me where I could find information (hopefully step by step) and what is the benefit of unit testing. I am a sole developer in a company, therefore I...
1
by: flashadow | last post by:
Who can explain. Can JsUnit test dynamic pages? A site uses Apache Tomcat for the start. A site consists of starting page in which is loaded 4 jsp pages. Functions that need testing take...
24
by: David | last post by:
Hi list. What strategies do you use to ensure correctness of new code? Specifically, if you've just written 100 new lines of Python code, then: 1) How do you test the new code? 2) How do...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.