473,411 Members | 2,014 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 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 2214

"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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.