how to unit test a multi-domain cookie based javascript library? - javascript

I would like to set up a kind of google analytics like javascript library.
I would like to write unit tests for this library that will be cookie intensive on a multi-domain basis.
This seems hard to test because I cannot find a way to use the javascript unit test framework i know for multi-page load tests (domain A.B.com changes location to C.D.com or to E.B.com ...)
Is there something I am missing here ?

I may have found a terrific answer with Node.js Zombie project.
Linked to one of the Node.js testing frameworks it shoud lead to an elegant solution.
maybe not totally real-life-browser based but elegant nonetheless.

Related

How to integrate QUnit tests into Yii

I have a Yii project that is starting to rely more heavily on javascript for a lot of its operation.
To achieve a decent level of test coverage I'd like to use QUnit to test the javascript. Much of the javascript relies on ajax calls to pick up data from models (e.g. lists of items in drop downs).
I'd like to be able to use my Yii fixtures to set the database to a known state before running the QUnit tests - does anyone know of a way to make this happen? Or can anyone suggest another javascript unit testing framework that works well with Yii?
I would take a look at Venus (www.venusjs.org). It works with QUnit (and other test libraries) and may give you something close to what you are looking for. If you have questions, I'd be happy to work with you. Disclaimer: I am the creator of Venus.

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

Examples of JavaScript RIAs with unit tests

Can anyone give me examples of large-scale JS apps (including AJAX, different UI widgets, and a sophisticated architecture) with unit tests?
I'm not talking about Selenium tests here, just plain ol' stupid unit tests using mocks, decent result reporting and such.
Not sure why people voted to close, or downvoted the question. Maybe a comment would be nice.
Seriously, I've been trying hard to find unit tested web apps, since I'm having a hard time building mocks and I wonder if it's even possible with reasonable effort. It made me think about the benefits of unit tests on widgets as compared to Selenium tests. People are babbling a lot about unit tests in theory but evidently nobody actually has done it in JS-RIAs. Or have they?
Personally I like Qooxdoo, check it out for your self and see if this is what you want
http://qooxdoo.org/demo#real-life_examples
This is one good tool: http://www.uize.com/
You should look at Jasmine & Sinon.js : http://sinonjs.org/
Here is a good tutorial on testing using Backbone.js, Jasmine & Sinon.js : http://tinnedfruit.com/2011/03/03/testing-backbone-apps-with-jasmine-sinon.html
I also recommend Phantom.js for integration testing... It's a headless browser and much faster than using Selenium... http://www.phantomjs.org/
Btw here is an example of unit-tested app from Pivotal : https://github.com/pivotal/cimonitor. You can find client-side tests there -> cimonitor/public/javascripts/js-common
I'm not sure if this answer will qualify but I'm working on the next iteration of my pet project "Atomic OS" (an OS-metaphor for web developers) which will, eventually, meet your criteria.
I'm working on a related project (which I can't share just yet) that is built on a bare-bones Atomic OS v2 foundation and provides a rich set of UI widgets for mobile web apps.
I built & use JSDog to produce documentation from a subset of JSDoc syntax and unit test runners with QUnit.
For an example of where I'm intending to go with unit tests, please see the Atomic OS documentation. (Click "Docs" in the taskbar and select a class, such as HxJSFS)
Just one perspective:
I work on a web application that is the front end of a video analytics system. (The back end is typically an IP camera, DVR or video router running a very, very lean, embedded web server.) It uses a number of jQueryUI widgets, allows user to configure the device, create video analysis rules, and draw markup over video frames using canvas elements. I think of it as fairly sophisticated.
We use unit tests (originally written for JSUnit, but now using qunit) for a very limited subset of the code. We have unit tests to verify the behavior of business objects, including the ability to serialize/deserialize to/from XML. And we have unit tests to test the basic geometry classes we've written for the canvas markup.
However, we have no unit tests that manipulate the DOM or that verify that the elements on a page are in the correct state. Doing that correctly struck us as too difficult a problem to solve, so we rely on Selinium tests to verify that a given set of inputs will put the DOM into the correct state.

Looking for Info on a Javascript Testing framework

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.

How do you know if a JavaScript library you are using will break your code after an upgrade?

So, you are using a bunch of javascript libraries in a website. Your javascript code calls the several APIs, but every once in a while after an upgrade, one of the API changes, and your code breaks, without you knowing it.
How do you prevent this from happening?
I'm mostly interested in javascript, but any answer regarding dynamically typed languages would be valuable.
I don't think there's much you can do. You always run a risk when updating any piece of software. The best advice is to:
Read and understand documentation about upgrading
Upgrade in your test environment
TEST
Roll out live when you are happy there are no regressions
You should consider building unit tests using tools such as JsUnit and Selenium. As long as your code passes the tests, you're good to go. If some tests fail, you would quickly identify what needs to be fixed.
As an example of a suite of Selenium tests, you can check the Google Maps API Tests, which you can download and run locally in your browser.
Well there are two options:
Don't upgrade
Retest everything after you upgrade.
There is no way to guarantee that an upgrade won't break something. Even if you have something that could check the underlying API and make sure it still all lines up, you can't be certain that the underlying functionality is the same.

Categories

Resources