Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to do integration testing for a Javascript heavy UI in a rails app?

We have a web application that makes extensive use of AJAXy Javascript in the UI. We have nearly complete code coverage of our backend using Shoulda and Webrat, and would like to extend our test suite to include full integration testing through the Javascript UI.

We tried Selenium but found it brittle and temperamental. Are there more reliable options?

UPDATE

For those still checking this out, we ended up using Xvfb so we can run Firefox without a screen. Allows us to run the test on a headless Jenkins CI server. We still have to run tests "live" locally occasionally to debug, but it works pretty well.

like image 268
Joshua Avatar asked Apr 05 '11 23:04

Joshua


People also ask

What is Rails integration test?

While unit tests make sure that individual parts of your application work, integration tests are used to test that different parts of your application work together.

What is integration test in Javascript?

Integration tests are used to test multiple, bigger units (components) in interaction, and can sometimes even span multiple systems. The purpose of integration tests is to find bugs in the connections and dependencies between various components, such as: Passing invalid or incorrectly ordered arguments.

What type of test is not typical in a Rails application?

Don't write view tests. You should be able to change copy or HTML classes without breaking your tests. Just assess critical view elements as part of your in-browser integration tests.

How do I run a test in rails?

2.7 The Rails Test Runner Or we can run a single test file by passing the bin/rails test command the filename containing the test cases. This will run all test methods from the test case. You can also run a particular test method from the test case by providing the -n or --name flag and the test's method name.


2 Answers

One of the JavaScript gurus where I work recently pointed out PhantomJS as an interesting tool for testing our JavaScript-heavy web applications. We haven't tried it out yet but the idea of a headless WebKit for DOM testing sounds promising to me.

like image 53
David Winslow Avatar answered Oct 29 '22 04:10

David Winslow


This is something I have been wrestling with for a while, as I am doing some work with ExtJS (a very powerful JavaScript UI builder for the browser) and Rails.

After having researched quite a few different options. I still haven't found a perfect solution for it. Ideally, I would be able to run them headless and just report on the output. Unfortunately, none of the emulators out there seem to be able to run JavaScript with full DOM support seamlessly (at least, none of the options I've found are). So that pretty much means that you have to run your full-powered JavaScript code in a real interpreter (such as a browser). Webrat with Selenium works acceptably well, assuming you're willing to deal with the pain of trying to path out your requests to the UI properly. If it's your own JavaScript that you're implementing it against, that may be easier. But when it comes to a third party UI library that you don't have much control over, it can certainly get, shall we say, interesting.

Probably not the most helpful response, but that has been my findings up to now!

like image 36
Christopher WJ Rueber Avatar answered Oct 29 '22 04:10

Christopher WJ Rueber