473,698 Members | 2,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2240

"Matt Kruse" <ne********@mat tkruse.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********@mat tkruse.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.javas cript 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.testSetTex tStyle = 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.inner HTML = data;
this._setSelect ion(10, null, 18, null, 'e 2line');
this.ui.setText Style('h2');
this.assertEqua ls(this.cleanHt ml(this.body.in nerHTML), 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 SelectionTestCa se in test_kupuhelper s.js.
Jul 23 '05 #4

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

Similar topics

14
2745
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
2162
by: Peter Rilling | last post by:
Does VS.NET 2005 Professional support integrated unit testing, or is that only with the team system?
1
1433
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, nothing happens after clicking run - or if I'm lucky, a window pops up, blank, other than the heading "Tracing - JSUnit". Any help would be appreciated
72
5246
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: http://geosoft.no/development/unittesting.html Thanks.
1
1321
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
18966
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 don't get expose to much of this technology. Thanks in advance. Regards Dat.
1
2186
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 information from a page and after processing return data to page using jQuery. And also need testing object which in a constructor has methods which also takes dynamic information from site. The library of jQuery, ajax, JSON is used in a site. Almost all...
24
2520
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 you ensure that the code will work correctly in the future? Short version:
0
8683
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9170
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8902
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8873
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.