Writing JS tests for Django apps - javascript

I have some django apps for which I have some templates. I have some inline JS in the template and a lot of DOM manipulations.
I would like to test the JS parts. I don't particularly want to use selenium - mostly as I don't want to run a selenium server and want to make my tests slow.
So my question is:
Can I write these tests with Qunit/Jasmine et all?
Can I integrate them with a CI?

The main problem with javascript testing is compatbility of all that fancy browser features you may use. I am not sure about the capabilities of Jasmine, but I'd take a look at PhantomJS and CasperJS, which are headless WebKit based browser automation environments.

Related

JavaScript autotesting in browsers without webdriver

I am developing a js library for smart tv embeded apps, and I would like to make some autotests for my code. The problem is, smarttv's do not provide webdriver interface, so it is impossible to use test runners like karma.
I need a solution that can be embedded to a custom HTML page, run tests by my scenario and log results to a div or console. Which test frameworks are capable of that?
Testcafe is most suitable E2E framework for your needs: http://devexpress.github.io/testcafe/
It does not require any additional capabilities from browser, and can be run at least with a stool if it has a browser and connection to the network.
See advanced usage with example and comparation with driver-based E2E tools here: https://60devs.com/functional-testing-of-web-applications-using-testcafe-and-nightwatch.html
So I ended up using https://github.com/substack/tape
Using this lib I bundle tests into a single js via webpack and run them directly inside a specially created smart tv app.
Automated tests is not clear question, so if you want unit tests you can use every unit test framework working in browser but it must be setup and this is not easy to be automated you will still need to run it manually.
But now is great solution called Suitest which is handling mainly TV platforms and write tests is easy even non-programmer guys, there is lot of ways and also CI integration option.
So it is easy to be configured to run automatically with each commit by some CI or whatever you want.

Selenium with C# and Javascript

In our project we are trying to figure out which approach would be better for testing from the below
1. Selenium with C#
2. Selenium with Java Script
I am able to find that C# require Selenium libraries and NUnit framework. However, is it possible to use MS Test instead of NUnit framework? We are using Visual Studio 2013.
Secondly, for JavaScript, I found that we need Standalone server to be run to execute the scripts. Is there any good framework available to implement selenium using Javascript?
If you are comfortable with javascript why not use Java with Eclispe and TestNG. This would not require a standalone server implementation to test.
You can consider the NUnit framework to be just a tool. You have lots of options with regards to C#: Xunit, Nunit, MSTest... Selenium is awesome. The question is more C# vs Javascript and which is better suited to your company. I worked at a place where everyone used C#, so naturally using C# for testing meant a lot of external support. You can also call Javascript code in C# if needed via Selenium. I do this in a few rare instances. For Javascript, you have specflow, protractor, and Jasmine which work well together.

How can I run my javascript tests in django?

So my project's python portion has lots of helpful python tests to ensure the codebase isn't falling apart. I want to do the same for the javascript I'm serving out of my static directory.
Can anyone recommend strategies for testing my javascript, especially if it's wrapped into the django test running framework?
Lookup to Lettuce http://lettuce.it/. You can simulate a lot of browser's behavior to test your javascript.
Development in django http://lettuce.it/recipes/django-lxml.html

Testing JavaScript in CakePHP

In my CakePHP project, I'd like to run unit-tests of my JavaScript codes for the views. I'm trying to use QUnit for testing JavaScript.
Is CakePHP's testing framework capable of integrating JavaScript tests?
Where should I put the test codes?
Is there any example or information for that?
Should I consider Selenium for this purpose?
It is a php framework, what makes you think you can test another
language with that?
I would not put them into webroot/js/test and disable access to that folder via .htaccess
in the live environment
http://qunitjs.com/cookbook/
Yes, because it sounds you want to test that the whole rendered page works. I'm not sure what you exactly want to test.

Unit testing a modular Javascript web-app

I am building a web app using BackboneJS and RequireJS and need to implement some form of unit testing for UI interaction and data retrieval via AJAX. I have come across QUnit and Jasmine but don't really know how I can integrate this into my app.
If I am testing things such as:
Is the user logged in alright?
Has the data been received from the server ok?
Does clicking a button trigger the expected response?
Do click events work on dynamically loaded html content?
Does the app respond correctly to changes in hash/push-state urls?
I would imagine the testing has to be directly integrated into my app so as to have access to specific JS objects, work with session specific data and respond to changes in push state URLs.
How can I integrate QUnit or Jasmine (or other suggestions) into my modular app to unit test such features?
Unit testing is really simple.
You make a test HTML page. You include QUnit/NodeUnit/Jasmine/TestLibraryOfChoice
You then use requireJS and load one of your javascript modules,
and you simply test the exported object or function. That means testing the valid inputs of your module and asserting the outputs are correct.
You may have to mock out ajax and write HTML mocks
Dojo Objective Harness (DOH) is a very good unit test framework, which is browser agnostic and supports testing asynchronous functions, see here for a walkthrough guide.
However, from your test cases it looks like you want something more like an integration test?
If so Selenium is a good browser automation tool.
Crucially, neither of these tools will require you to modify your code (unless you find bugs :))
If you want to see an example where requireJS based modules are unit tested with QUnit, download the javascript reference architecture at http://boilerplatejs.org.
Disclaimer: I'm the main author of it.

Categories