Looking for Info on a Javascript Testing framework - javascript

Hi Can somebody fill me in on JavaScript Testing Frameworks?
I'm working on a project now and as the JS (Mostly jQuery) libraries grow, it's getting more and more difficult to introduce change or refactor, because I have no way of guaranteeing the accuracy of the code without manually testing everything.
I don't really know anything about JavaScript Testing Frameworks, or how they integrate/operate in a .Net project, so I thought I'd ask here.
What would a good testing framework be for .Net?
What does a JavaScript test look like? (e.g. with NUnit, I have [TestFixture] classes & [Test] methods in a ProjectTests assembly)
How do I run a javascript test?
What are the conceptual differences between testing JS & testing C#?
Is there anything else that would be worth knowing?
Thanks
Dave

As for jQuery testing(and Javascript testing in general) you should maybe take a look at QUint, jQuerys testing suite. You simply include a couple of javascript-files, and a css-stylesheet, write your testes in the same document(or if you want to include them of course), and open the document. The testing framework sets up the page, and lets you run the test.
As for implementation with C# and .Net I can't help you.

Already lot of questions (and replies) about this subject on stack overflow:
The most complete: What are some JavaScript Unit Testing and Mocking Frameworks you have used?
Looking for a better JavaScript unit test tool
Javascript Unit-testing?

You should at least be aware of jsUnit.

Related

Frameworks and tools for UI testing of ExtJS based web apps

I would like to test a web app that was drastically redesigned to use ExtJS to drive its UI.
I have done some online searching but couldn't find any recommendation for a good framework to handle it properly.
Up till now we have been using WatiN to create tests.
Note that we do not own the web app code.
What are the best options currently available?
You should look at using Siesta, it's a unit testing and functional testing tool designed to help you test Ext JS and Sencha Touch (and it's also used by Sencha internally to test Ext JS itself). Since Siesta knows a lot about Ext JS you can write expressive tests using Component Query instead of CSS and get much more robust test compared to simpler tools described in other answers in this thread. Here's a sample test script in plain JS:
t.chain(
{ click : ">>textfield[name=user]" },
{ type : "Mike[TAB]Password" },
{ click : ">>button[name=loginbutton]" }
);
DISCLAIMER: I work for the company that created it.
http://www.bryntum.com/products/siesta/
Are you looking to do a straight functional test of your web page or are you looking to narrow your tests specifically to the JavaScript in ExtJS?
If it's the former (functional at the UI level), then WatiN/Watir/Webdriver ought to work for you. (If they're not working then I'd love to get more details around specific issues you're running in to.)
If it's the latter then you might investigate Jasmine which gives a lot of interesting capabilities around unit testing your JavaScript at the UI layer.
(If it's functional testing, you might also check out Telerik's Test Studio for functional automation. I'm the Evangelist for that tool, so I'm a bit biased...)
You may want to look at RIATest.
Version 5.0 fully supports ExtJS testing. ExtJS UI widgets are first class citizen in RIATest. This means that unlike other HTML testing tools you do not need to write tests that manipulate the HTML DOM elements. The tests in RIATest operate in terms of ExtJS UI widgets.
Examples of RIATest scripts that work with ExtJS widgets:
The following clicks on an ExtJS button with label "Next Page":
ExtButton("Next Page")=>click();
And the following does drag-n-drop of a row from one ExtJS tree to another:
ExtRow("Controller.js")=>dragAndDropTo(ExtTreePanel("#tree2")->ExtRow("Custom Ext JS"));
And this collapses the header of an ExtJS box:
ExtBox("Feeds")->ExtHeader("FeedsВ")->ExtCollapser()=>click();
(All sample code above is from real test scripts that run on ExtJS sample applications).
RIATest also knows when to automatically wait for ExtJS AJAX to finish, so if your UI does dynamic content downloading the tests will auto-magically wait until data is received from server.
(Disclaimer: I am a RIATest team member).
Sahi is an automation and testing tool I have recently come around as I am in a similar search as you... Selenium hasnt worked for me (as it hasnt for many around the web... havent found anything to make it work... dynamic IDs and other Ext related particularities mess with it apparently)...
take a look at sahi maybe it will be useful... www.sahi.co.in (I have no relation, I discovered it recently and found it useful).
You want to do Functional Testing. Selenium is a good choice. It has API implementations in a slew of languages (Java, Ruby, Python) and it uses Webdriver under the covers.
Ranorex can handle Ext-Js as well, although turning it into first class citizens will require some custom coding. The secret in general is to avoid using id's for object recognition, as they change around and use innertext property instead.
Personally found using xpath with extjs flaky in places.
You're better off (in Java) writing a method which uses a JavaScript component query to pull out the element id. (if it has one)

Continuous JavaScript Testing

Does anyone know of a good JavaScript testing tool which integrates automated testing with your Testing Framework of Choice. I am aware of TestSwarm (which is not automated testing) and Travis-CI (which isn't really available for closed-source projects).
Any other ones out there?
You can use Selenium:
Its test can either be generated by its IDE, or can be written in high level languages such as Java, PHP, etc.
Its can be instantiated from a Command-Line.
Its can be integrated with continuous-integration servers like Jenkins (In-build plugin).
The fact, that it can be instantiated from command-line (preferably written in java), makes it integrable by any CI Server
Two that I know of (although I'm not sure they are really meant for this purpose...) are Simple Test js and the MIT project Sikuli. Sikuli is great for making a cursor click on things and test out the user interactions. Neither one of these naturally will integrate well with your testing framework of choice but they will certainly allow you to write unit tests. Hopefully someone else will know of a better solution.

What is the best way to test javascript?

I'm building several jQuery plugin and going ahead I thought that will be useful to know some best practice for testing my code in order to be solid.
I usually use Selenium but this just for debugging.
I'd like to know the best way for doing some real test (like TDD, BDD, DDD) for my code.
Any suggestion will be appreciated.
I use Jasmine https://github.com/pivotal/jasmine and would highly recommend it.
I don't think there is a "best" framework for test your code. I just know that you "should" test your code. So with that said, just find a test/spec framework your like and get testing!
I also at times use https://github.com/webadvanced/jMoney for testing small bits of code or for testing prototype code. It displays results in the console and does not require any setup or dependent files.
If you are more of a TDD guy, you can try QUnit http://docs.jquery.com/QUnit

unit testing ajax in .net

How you test ajax? What do you use?
Share information.
For me, testing ayah was torture.
I'm using jsUnit and mockajax but, nothing works...
help me please.
I know this question is a bit old, but I just wrote a framework for doing JavaScript unit testing (and coverage) in .net. So just write your ajax unit tests in what ever JS framework u want (like qUnit, JSUnit, closure, etc) and use my project to provide bindings to .Net. Allows you to use Visual Studio and your standard CI tools to run your tests.
https://github.com/gatapia/js.net
Let me know what u think.
Thanks
Guido

Using Javascript/jQuery is there any reason you would use YUITest over QUnit as a testing framework?

Hi i'm starting a new website and am going to be using jQuery as the library in the browser.
I was looking at testing frameworks and the obvious choice for Unit Testing in jQuery is the framework jQuery itself provides which is QUnit.
I have also looked a little at YUITest which looks very well documented. So my question is.
If you are programming the clientside in Javascript/jQuery is there any
reason one would use YUITest over QUnit as a testing framework?
Yui test is providing much more features than qunit, eg. asynchronous testing and also mocking.
Also the documentation is far better.
It's really worth to have a look at Yui test.

Categories

Resources