Until now, I've done all my testing with just Jasmine and jQuery to automate the browser. I am starting to explore Karma but it seems to be set up only for unit tests that involve loading HTML fragments as test fixtures and I find no way to load a whole web page. Am I missing something or is this simply the wrong tool for what I am trying to do?
From the karma FAQ's section:
Can I use Karma to do end to end testing?
Karma has primarily been designed for low level (unit) testing. If it's an AngularJS app, you can use Karma with the karma-ng-scenario plugin. However, we recommend Protractor for high-level testing.
Typically, loading a whole web page goes beyond the scope of single units of code: you need to spin up a browser, load the page and make your actions and assertions. End-to-end testing frameworks like Protractor, Nightwatch.js or Webdriver.io might be more suitable for this specific case.
You can do integration testing using the following toolchain:
Karma ➔ Mocha ➔ Mocha-CasperJS ➔ CasperJS.
Check out the mocha-casperjs package.
Related
I would like to end-to-end test my Meteor/React app in multiple browsers.
Karma is great for automating tests in multiple browsers, but I don't see any config options to make it load the page to test from my own server, only the option to specify which JS files contain tests and support code.
This is obviously because Karma injects its own test harness HTML and JS. But to end-to-end test my page, I would need it to load the page from Meteor instead of Karma's own embedded server, since Meteor injects a lot of its own JS dependencies into the page.
Bundling the tests into the code served up by Meteor is easy. The problem is how to tell Karma to load a specific URL, and to be able to put script tags or whatever to load and run the Karma test harness into my own HTML code.
I believe it may have been possible with the Velocity test runner for Meteor, but I found it horribly slow and wanted to implement end-to-end testing without it.
Does anyone know if this is possible with Karma or another framework?
I have got javascript tests running in visual studio using Resharper and Jasmine. It all works fine. Now however I want to run an integration test. After looking into this I just can't work out whether I should be using Karma or PhantomJs or both? And whether they link to resharper?
I then have to run all my tests on the continuous integration server using Team City. Doesn't seem like there is a clear logical way to architect front end testing from dev right through to the CI server.
For example do I really need to use Karma locally and on the CI server? I don't want to because it is not baked into visual studio and I will have to keep opening the command line and running my tests manually. This will annoy other developers and they won't bother running them I imagine. Help!
We are using Team City by the way....
Neither of these test runners are connected to Resharper in any form. I don't think there is a one and only "correct" way of running Jasmine tests in TeamCity currently - for all approaches I am aware of there is a bit of assembly required.
Personally I am using a combination of PhantomJS and the Jasmine TeamCity Reporter which works like this:
Get a list of unique test URLs from server - each of these test suites will use the Jasmine TeamCity Reporter to log results
for each test URL dynamically generate a test JS file to be used for phantom and write it to disk
use PhantomJS to run the JS file which now will load the test suite page and its test result will be written to console where they are picked up by TeamCity.
I am trying to choose a setup for testing a webapp that uses Backbone and RequireJS.
I will try to do most of my unit testing from javascript and I am in doubt whether it is better to load my whole app before calling the testing framework or to use RequireJS to dinamycally load just the modules that are being tested by each test.
As this site is just for Q&A and not open to discussion, I will reformulate: Do you have any strong argument against not loading the whole app upfront when unit testing?
The best way is to test each of your Models/Collections/Views separately in unit test. Starting the whole app in a unit test would it made really hard to test all cases for a module. As you mention requireJS you should also mock most of the dependencies of a module using squireJS.
But you should additionally have some integration tests where you test the behavior of the whole app in a headless browser using a tool like selenium, casperJS or capybara.
With requirejs, there are two ways for you to interpret loading upfront:
During development, where r.js is not be used, and just depend on configuration on requirejs.config
After r.js optimization, where the modules can be restructure by r.js configuration
Im searching for a decent test runner and unit testing framework for Javascript. My candidates are Karma and Mocha. Previously I used JsTestDriver, where adding HTML fixtures was easy, but I cant find a way how to load HTML fragments and access it from Mocha tests using Karma testrunner
I have a demo that uses html fixtures with jasmine here and the demo description contains links to a screencast and github repo for running with Karma. See this link.
The final solution was Karma testrunner combined with RequireJS, which has a text plugin making the loading of HTML fixtures really easy.
A working example can be seen at this Minesweeper game. It's still in development phase, but the the libraries and structuring are working.
I've been writing JavaScript unit tests using Jasmine. However, those tests run inside a browser, not as part of MSTest.
I want my TFS Continuous Integration builds to break when a JavaScript unit test fails. I know there is a solution for this in Visual Studio 2012, but I'm on 2010 (and will be for a long time in the future probably).
Is there an easy way to integrate Jasmine based JavaScript unit tests with TFS Build?
The Chutzpah test runner enables you to run your QUnit and Jasmine JavaScript unit tests from the command line or Visual Studio.
Therefore you should be able to integrate it into your TFS build via the InvokeProcess activity.
I'd use nodejs + jasmine-node, but you can also look at http://phantomjs.org/ with a junit reporter. Jasmine-node provides a junit reporter with the --junitreport output. You might also look at the TFS Build Extensions (http://visualstudiogallery.msdn.microsoft.com/2d7c8577-54b8-47ce-82a5-8649f579dcb6/view/Discussions/) and the activities in there. It includes a xml transform for JUnit to TRX (test results xml) which can be pushed into TFS.