Javascript unittesting frameworks - javascript

I am loooking for a javascript unittesing framework and trying to decide if I should go with JSunit or not. My goal is to have the unittests run with my CI, possibly using a JSunit server that is running headless.
From people's experience, is this a good idea? Are there better frameworks that you would recommend for my goals, over JSunit?

QUnit is worth reviewing

It depends on your requirements. If you are going to have to test DOM intensive code and need your tests put in separate pages and organized in suites I would recommend using JSUnit. It has a nice test runner, supports suites and fixtures as separate pages. The experience is much like any other xUnit framework.

I have used JS Unit Test, not JS Unit, in an automated test environment, but it was run through Selenium. Using env.js or HTMLUnit you can create headless tests with most any JS unit testing library.
Personally I don't go headless. A headless browser is often an "ideal" browser and might not catch all those browser quirks. So I ultimately run my browser tests through a browser using Selenium. I use the Sauce Labs jar.
For other testing frameworks is a list on Wikipedia, Screw Unit looks nice if you like BDD.

Related

jasmine-jquery vs selenium drivers (like Nightwatch.js) - when to choose each of those?

I would like to add integration tests to an (Backbone.js) application I am maintaining, and considering what strategy is preferable and upsides and downsides for each:
Running tests on the client side, with something like jasmine-jquery. Ideally I would like something like ember test helpers which allows writing simple synchronous looking code (while actually running async).
Running tests on the server side using selenium drivers, for example Nightwatch.js.
It is hard to tell which approach has more community and tooling around it, and which projects are more mature. Additionally, I am getting the feeling that running tests on the client side might allow better isolation of tests, while running on the server side, might create tests which run longer and heavier (also to maintain?) but allow to simulate more complex real-user scenarios
Any thoughts would be appreciated
If you care about browser compatibility, then you'll want to run end-to-end tests on different browsers on different platforms, possibly using a cloud-based cross-browser testing service such as SauceLabs, BrowserStack, TestingBot or CrossBrowserTesting.
Since you're using Backbone and are familiar with JavaScript, you might want to pick a JavaScript client for Selenium WebDriver. There are quite a few choices, with Intern leading the pack by far.

Test Driven JavaScript Development with Django vs Node.js

I have a web project coded 80% in JavaScript and 20% in Django without a single unit testing as I rushed for Minimum Marketing Features. Now that the project is getting funded, I decided to invest some time to introduce TDD. I had a great deal of inspiration from this KickStarter-funded tutorial.
http://www.letscodejavascript.com/
The author uses Node.js, Jake, Lint, Nodeunit, and Karma to simplify the whole integration process. The server/client tests in all major browsers is done in a single command and I was really hooked to this idea, but it requires switching to Node.js.
I've searched for TDD in Django and ran into this tutorial that makes use of Selenium.
http://www.tdd-django-tutorial.com/
However this TDD was primarily based on unit testing in server. Here are the questions.
Can multiple client JavaScript testing be done in Django/Python?
I assume the answer is no since js files are nothing more than static library in Django. Correct me if I'm wrong.
Is it worth using Node.js just for the sake of TDD Javascript?
My logic was either you use Python or Node.js for the server, but since tools like Karma and Buster.js requires Node.js, I was wondering whether setting up the Node.js alongside Django just for multiple client testing is plausible choice when considering lower cost of maintenance.
Thank you :D
You can take a look at using selenium in your django test suite. Django's official docs cover this in moderate detail
To answer your question about Node.js - I would say that it's probably not worth the complexity to add node.js SOLELY for the purpose of running unit tests. Also, since your javascript is likely built to run in a browser, it's less likely that things will break down if you use a tool like selenium (which runs the code in an actual browser, providing a python scripting interface).

Is it possible to use Testacular for non-AngularJS app for end-to-end testing

I'm building a simple app and want to use Testacular as the test runner. Testacular is simple to setup for unit testing but the possibility of using it for e2e also seems great, however my app will not be in AngularJS. Is this possible (or simple) to do or should I be looking more towards Selenium?
Yep! From Testacular's GH Page:
Testing Framework Agnostic
Describe your tests with Jasmine, Mocha, QUnit. Or write a simple adapter for any framework
you like.
Since the aforementioned testing frameworks aren't library-dependent, it would make sense that as long as you can test your library code using one of those frameworks you can use testacular to provide a test-runner for it.
That being said testacular is not selenium. It allows you to test your code in a browser environment but as far as I know doesn't provide navigation, DOM Querying, user-emulation etc. like selenium does. If you're looking for selenium functionality for your JS code you should check out Soda which is an awesome library written by TJ and the rest of the gods on Mt. Olympus ::cough:: I mean developers at LearnBoost that provides a JS adapter for selenium's wire protocol, among other things.
But if you still think testacular is the way to go then take a look at their sample configuration file which should get you started in the right direction. Hope this helps!

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.

unit testing modular javascript

I am currently deriving a javascript framework pattern as an architecture for the client side development for an upcoming large scale application that I will developing.
I am looking to go with a module observer pattern in which each control I develop will have its own javascript file, holding no knoweldge of the other controls.
From designing this framework for my application, I am looking to integrate in a testing mechanism for my modules - a unit testing mechanism for javascript. I am not aware of any such frameworks or how I may set up such. Any suggestions?
As part of such testing, I will also need to mock up http requests.
The library I will be using in development is jquery.
The JQuery team has QUnit.
As for abstracting out AJAX, you should wrap it appropriately or just test the data manipulation methods.
Jasmine may be what you are looking for. It has built-in mock up support, and does not rely on any other frameworks.
They also have a separate module for faking AJAX responses.
The setup is simple. Just download the standalone version, write some testing suites, and view the SpecRunner.html in a browser.
Consider using JsTestDriver to run your JS tests. The main benefit it provides - it can run your tests on continuous integration environment, which is essential for unit testing practice.
Some additional features:
It can be used along with QUnit and other testing frameworks.
It can execute your tests in parallel across multiple browser.
It supports calculation code coverage.
List of mocking libraries you can find in another thread.
BoilerplateJS
is a reference architecture for large scale JavaScript product development. You can find the tests which are written using qunit, sinon and testr included under the tests folder.

Categories

Resources