Karma-Jasmine with AngularJS realtime project - angularjs

I have gone through several tutorials but none could really help me out.
I have also read through the documentation, which is easy for beginner test cases like to test for an array/string, etc. But i need some help in using it in a full-time project.
How to write these unit tests for not-so-simple cases like, matching what is displayed on the website is what should be expected?
Thanks!

Related

Enquiry about Selenium webdriver

Hi i am new to selenium webdriver testing. We have a test project at our company and i am trying to understand the basics. I know a little bit to help me code simple test. I want to know if there are any possibilities to have two group names for one test like
#Test(groups = {"group1", "group2"})
and make the test work by including group1 in one suite and group2 in another suite, also is there multiple dependency groupings like
dependsOnGroups = {"group1", "group2"}
i am trying to understand the framework so any comments is welcome, but pleasr try to keep it simple. Thank you in advance
As far as I know, WebDriver does not have that kind of feature. If I understand your problem correctly, you need to use unit testing framework. What language are you using to code tests with webdriver? If java, I reccomend using JUnit - check out documentation and search web a little, you are probably interested in topic of Test Suites, which are used to grouping tests.

How to test AngularJS App using Karma/Jasmine

Till now I have been reading the Angular JS official docs, and some other sites which have demonstrated Unit testing in Angular JS. But all of them have just started the explanation with an example file which contains some test code. But nowhere could I find the Pre-steps to write the unit testing code. Something like, where do we write our test cases? any Specific folder location? How to run the tests etc. Can anyone please guide?
Really appreciate the help and time spent on the question.
The question where to put the unit tests is more like a matter of personal taste and which directory layout you choose. I prefer a feature-driven layout, putting all files for a feature in a directory and that includes the unit tests as well. If you do that, you have to follow certain naming conventions like:
myfeature.module.js
myfeature.controller.js
myfeature.controller.spec.js /* this is the unit test */
myfeature.html
myfeature.less
I suggest reading the angular styleguide from John Papa and if you want to get kickstarted, use one of the generators out there. In my one (cc-angular) I tried to stick to these rules and jasmine with karma and e2e tests are built in.

Adding functional tests to a Backbone.js application

I'm sorry if this question isn't appropriate: I'm new to test-driven development, especially on JavaScript.
I have a working Backbone.js application, and I'd like to add some JavaScript tests to it. But I don't really know where to start.
Specifically, I'd like to write tests that are passed a URL, and check that the rendered page contains particular DOM elements. (So functional tests, rather than unit tests, I guess.)
What is a good way to do this? Could anyone recommend good practical resources for getting tests like this up and running?
Apologies for the newbie question.
I have faced the same problem lately and Ryan Roemer book Backbone.js Testing (http://backbone-testing.com/) is a great place to start.
His process is not purely TDD, but he gives some nice tips.
When taking it to practice, I will recommend a Yeoman generator like:
https://github.com/mrichard/generator-marionette (Marionette)
https://github.com/revathskumar/generator-backbone-mocha (Backbone and Mocha)
https://github.com/richistron/generator-cornelio (Karma and Backbone)
They will save you some time on the setup. Also, if you are using Rails, Konacha https://github.com/jfirebaugh/konacha has been pretty handy for me.
Good testing!
Selenium is on de-factor way to run functional tests in the browser. Selenium has a firefox plugin that will record actions and replay them. That would be the easiest way to start. You can look at Selenium's API docs to write code to interact with the browser.
Sause Labs (http://saucelabs.com/docs/quickstart) has selenium in the cloud which is useful so you don't need to have a browser window open on you desktop and run the tests. PhantomJS can also run a "headless" browser (it does't open a window on you computer, just runs in the background).
Once you have selenium working you might want to look into acceptance testing. The tests are written in plain english use Gherkin (or similar) syntax and it runs functions to run the test and output reports if there were errors or not.
I wrote an article how to use Selenium for Acceptance Testing http://alex-craft.com/blog/2014/acceptance-testing-for-web-app
Tools: WebDriver (Selenium or Phantom.js), wd.js, node.js, mocha.js.
There's an example with explanation how to use meaningful names instead of CSS selectors, eventual conditions, etc.

Integrating karma-runner and cucumberjs

Has anyone used karma-runner/testacular to execute cucumberjs tests? I suspect that I may have to write an adapter like the Jasmine adapter. Any knowledge on integrating a test library with karam-runner would be much appreciated.
I'm currently using an adapter I wrote: https://npmjs.org/package/karma-cucumberjs
It's been working fine for me, I'm now using it on a second project. But I am sure there are changes that I could do to it once people start using it and finding things they wish it did. Let me know if there are any problems, you can email me at s9tpepper#apache.org or just use the GitHub issues on the repository. I don't check StackOverflow all that much unless I'm looking for an answer to a specific question.
This seems to be something people want. Jon Perl started karma-cucumber recently. It does not include a Karma reporter for Cucumber.js yet but seems to be the plan.
I'll also be looking into this in the near future.

How to implement Backbone boilerplate with views

I am trying to learn backbone, however truth be told, I'm feeling a little overwhelmed. Everywhere I look it is being done in a slightly different way, each with more frameworks and plugins to learn. So I have decided to put my faith in Addy Osmani and am reading his Backbone Fundamentals book. I have followed his recommendation and used the Backbone-Boilerplate. However for whatever reason, I have been unable to successfully install Grunt BBB so I cannot download the working examples.
What I am trying to do is follow this router section and use views. http://addyosmani.github.com/backbone-fundamentals/#router.js.
The problem is that I think these instructions are incomplete. For a start the collection.fetch() variable is in the wrong scope, and I really am not understanding where I need to place the views and how. I am pretty sure that if I could see a working example of this I could understand it, but as I said, everywhere I look its a different implementation.
Does anyone know how to use the backbone-boilerplate with routers and views? Are there any working examples anywhere?
Let me make a suggestion. A couple of months ago, I was where you are now: trying to learn backbone and trying to follow best practices while I did so. Like you, I came across Addy Osmani's book and like you I tried getting stated with backbone-boilerplate.
After much stumbling around, I eventually concluded that backbone-boilerplate was not something I needed to have while I was just learning backbone. It is now, only after having created a fully working, non-trivial CRUD application that I start to see how I might incorporate backbone-boilerplate. I think you probably need to be asking the questions that backbone-boilerplate answers (How can I break up my application into modules?, etc.) before you attempt to incorporate another framework or plugin. The same goes for Backbone.Marionette: great library, but you really need to have something to apply it to before using it.
Starting out, I would suggest having just a single file for all your backbone code.
One of the things that really helped me out was playing around with and extending various jsfiddle demos people had created using backbone. A simple google search will turn up quite a few. I found it a great way to learn as I was able to manipulate working code and get immediate feedback on what worked and what was allowed.
And although backbone is a client-side library, it's often simpler and faster just to ignore html and write stuff out to the console.
Finally, if you're willing to pay for it, I highly recommend Liam McLennan's set of backbone.js training videos on pluralsight.

Resources