8

For Javascript some testing-frameworks exist, like JSUnit or js-test-driver. They are fine, but they run the tests in a browser. That's fine, especially to verify your webapp is running in different browsers. But on out continuous-integration-server no window-system (and no browser) is installed. So is there a way to run the tests without the usage of a browser? The best would be to use one of the existing frameworks, so that developers can locally run the tests in their browsers and the continuous-integration-system runs them browserless.

3
  • 2
    It's not an answer to your question, but I would suggest testing the thing in a real browser. This is what the end-users will see, so this should be tested. What OS is the CI installed on? Commented Jul 10, 2009 at 12:18
  • 1
    The CI is installed on linux, but without a X. So testing in a browser is not possible on the CI-server. In the browsers it will be tested by the developers anyway, but I want to add the tests also to CI. Commented Jul 10, 2009 at 12:28
  • How about phantomjs ? Commented Jun 25, 2013 at 17:29

6 Answers 6

1

You may be interested in HtmlUnit which is used by several UI-testing framework like WebDriver

Sign up to request clarification or add additional context in comments.

Comments

1

jsTest can be run command line or as an eclipse plugin.

However, be careful, you will not get 100% code coverage using a tool like this if you need to support multiple browsers. Each browser implements JavaScript differently (i.e.: IE). Therefore, the only way to fully test your JavaScript is to run the tests in all browsers that you support.

2 Comments

I'm not sure why you say you can't get 100% coverage. Coverage means that the code gets executed. The problem you point to (cross-browser compatibility) is that the same code might mean (and do) different things in different execution environments. The implication of that is that if you have 100% coverage in Firefox, it might not tell you all you want to know about the code's behavior in IE. You can get 100% coverage without getting 100% knowledge. (And even 100% coverage in all browsers is not the same as 100% knowledge, but that's a different issue.)
This was 5 years ago. Web development back then was full of browser-dependent bifurcations since the APIs were so disparate. If you ran your test in Firefox, some command line runner, etc. you could not execute any of the code in the other branch that handled another browser. Since you're leaving half your branches untested, you cannot claim 100% code coverage. Nowadays, the landscape is a lot different. I honestly can't remember the last time I had to do different things for different browsers.
1

Take a look at the following articles:

In addition, we have a jsTestDriver server running with a couple of web browsers (as remote console runners) as a resource for Jenkins, so you can have CI with testing in web browsers.

Comments

0

I believe Canoo WebTest can be run without a browser. It's basically a frontend-testing framework but can be used to test JavaScript as well:

http://webtest.canoo.com/

Comments

0

JSpec can be run without a browser (using Rhino). But also supports being run in browsers as well.

http://visionmedia.github.com/jspec/

It also provides a nice specification style syntax:

describe 'ShoppingCart'   
  describe 'addProduct'   
    it 'should add a product'  
      cart.addProduct('cookie') 
      cart.addProduct('icecream') 
      cart.should.have 2, 'products'   
    end   
  end 
end

By running all your unit tests outside of a browser, you also get the benefits of ensuring separation of your logic from the html/presentation layer (useful for web apps, possibly overkill for small scripts).

1 Comment

The jspec project is dead and, before their site disappeared entirely, recommended Jasmine instead. stackoverflow.com/questions/3912312/jspec-no-longer-supported
0

Jasmine will run quite happily inside of node.js.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.