Unit testing tool for Javascript applications

Hello…
Could someone please tell me whether I can use Java Language to develop an automatic unit testing tool for Javascript functions or whether I should go for Javascript itself?
And may I please know all difficulties I might face if I would be using Java instead of Javascript itself to develop the testing tool.

Many many thanks,
Dani_zone

Hi Dani_zone, welcome to the forums

Interesting thought.

Most Unit tests I’ve seen are written in the language they’re testing. eg.
Ruby in Ruby
PHP in PHP
Python in Python
etc.

But as Javascript is client-side it might actually be better and/or easier to write the Unit tests in another language.
Though I think you’l at least need to use Javascript to do the Submits.and function calls.

There are more and more js testing frameworks coming out. I would check out http://www.manning.com/resig/ for some ideas as to how to approach it from the guy who created jquery. I haven’t had enough seat time with any of the frameworks to know which one to use.

What I have had some seat time with is using selenium to build integration tests – it can fire up browsers and hit your QA sites and run the full-blown site with scripts there so you can get end to end tests. You can hook into that using your server-side language of choice through a few means, check out http://docs.seleniumhq.org/ for details. But that certainly isn’t a unit test though half the time when people ask for unit tests they are really asking for automated testing frameworks.

Resig developed a unit testing framework for JS which is now called QUnit. [URL=“http://pivotal.github.io/jasmine/”]Jasmine seems to be very popular in the JS community at the moment - it’s more for BDD than unit testing, so it really depends what you prefer.

Hi Mittineague… could you please elaborate a little more in last part where you mentioned that I will be using
Javascript to do the submits.
so you mean Java would be fine if I would be using this language to develop the tool? Any problem I would be facing in future according to you?

I have yet to see successful JavaScript Unit test. I wasn’t in the team but it failed miserably due to how sensitive the test can fail w/ minor changes. It would take more time fixing the tests then implementing the business logic. I did hear a way that you can build Unit test based on screen capture. This would be a lot easier to test. For example, if user logs in then it must match this screen shot. If an error occurs during login, then it must match this screen shot. I forget the name but I’m sure google will help.

If you truly want to test using Java then I’d suggest GWT. I don’t think you need to use GWT in providing the UI javascript but use it to create whatever JavaScript you need. The beauty of it is that the source is written in Java, which means it’s very easily testable using JUnit.

I may have been wrong in my assumptions. I was unaware of any application being able to automate browsers. Going by the reply made by wwb_99

selenium to build integration tests – it can fire up browsers and hit your QA sites and run the full-blown site with scripts there

If it can work with

Java, C#, Python, Ruby, PHP, Perl, Javascript

it sounds very promising.

So Mittineague, you mean that I can use Java for developing the unit testing tool for Javascript functions?
but I wanted to know why all the existing tools are developped in JavaScript itself and that no one has developed it another language?
Any specific reason for this?
And if I am using Java for the tool how to start with everything?

Why use JS for JS testing? Simply because unit testing in a language should not require you to learn another language.

There are a number of unit testing tools for JS written in JS, the few mentioned above and YUI Test and Mocha being note worthy.

But if you were following recent JS trends, lately there’s some news going on about BrowserSworm: http://www.browserswarm.com

Thanks lots for providing the above link.