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.
Related
I want to build a web crawler/scraper web application using angular. Idea is to use client-side for making all http requests. Using a headless browser can take away much of the pain in parsing Html and evaluation JS code. Are there any headless JS-based browsers I can use?
I read about headless chrome and puppeteer. It turns out it can be used only from command line for running tests and not like a typical library which can work with angular. Or is there a way?
I am a scraper myself. This is how I solved the problem
get the html content using http/fetch
create an Iframe
Provide the string html content.
I am currently creating a solution using the same strategy above. Hope it helps.
Edit1: Do let me know in case you need a working demo. I feel its straightforward.
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.
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.
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.
Is it possible to check the validity of your JavaScript code, even modern techniques and JavaScript calls with some form of validity checker? I have seen some that check JavaScript but about with the combination of your HTML document, possibly with CSS, possibly 'src' include path, etc?
And what are the normal approaches for this type of testing?
JS Unit - https://github.com/pivotal/jsunit : Simple JavaScript unit test framework. Use it to check your code.
Selenium - http://seleniumhq.org/ : Use it to test your sites interface.
Use http://browsershots.org/ (free) to test the look of your site in different rendering engines.
If you maintain some semblance of testing there should be no need to make sure your code "validates", as perfectly valid code carries no guarantee of doing what you want it to.
If you're doing interface testing it's best to go with a framework like Selenium : http://seleniumhq.org/
You can create test suites and run them automatically when you do changes to your front end to make sure everything is still working as you expect.