This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
The Classroom Protocol• Few Administrative Formalities
– Sign in the attendance sheet, if provided– Fill-in the feedback at the end of sessions, if provided
• Derive Maximum Value– Ask questions, any time– Participate in discussions and lab exercises– Avoid brining personal or office work to the class room– Stay away from internet while class in the session
• Lets Learn Together– Switch-off or mute personal phones– Leave/enter the class room without disturbing the class– Take phone calls outside the class room– Keep the class room clean and professional– No cross discussions
• Reference Material– Download from http://www.glarimy.com – No Print/CD. Protect Environment
Krishna Mohan Koyya• Career spanning across 17 years
– 9 Years into Software Engineering with Cisco Systems, Wipro/Lucent and HP– 6 Years as Principle Consultant and Founder of Glarimy Technology Services– 1 Year as CEO at Sudhari IT Solutions, Bangalore– 1 Year as HoD at Sasi Institute of Technology and Engineering, Tadepalligudem,
• Technology Expertise– Distributed Systems and Network Management Systems– Object Oriented Systems Development– Infrastructure, Middleware and Web Layers with Java and Javascript
• Academics– M.Tech (Computer Science & Tech) from Andhra University, Visakhapatnam– BE (Electronics & Comm. Engg) from SRKR Engg. College, Bhimavaram
– AngularJS is built on the concepts of Dependency Injection and Single Responsibility
– Naturally, this approach makes it testable
• Test Specifications with Jasmine– Jasmine is one of the popular test frameworks for JavaScript applications– Same can be used for AngularJS as well– Jasmine offers rich set of matchers (for assertions) and spies (for mocking)
• Running the tests using Karma– Karma is one of the popular test runners– Developed by Google and recommended for AngularJS– Can run the Jasmine test specifications– Can be integrated with many other eco-system frameworks of AngularJS– Distributed as a NodeJS package
Testing AngularJS Using Jasmine and Karma@2014, Glarimy | www.glarimy.com | [email protected]
Setting-up the Environment• Install NodeJS
– Download it from http://nodejs.org/download/– Run the installer (available for Windows and Mac) – Setup the distributes (on Ubuntu and etc.,)
• Install Node Package Manager (npm)– Comes with NodeJS, by default– Command line tool to manage dependencies– Accesses node registry to download and install packages
• Install Karma– npm install –g karma– Needs internet connection to access the https://www.npmjs.org/ registry
• Install Karma Command Line Interface– npm install –g karma-cli– Needs internet connection to access the https://www.npmjs.org/ registry
Setting-up the Environment• Generate the karma-configuration file
– karma init glarimy.config.js• Answer interactive questions• Opt for jasmine as the test framework• Choose your browser• Provide an expression/s for matching the test files (like *.js, *.test.js and etc., )• Provide an expression/s for exclusions from the above
• Develop Jasmine Test Cases– The location of the test cases must match the file entries in the karma
configuration file
• Run the test cases– karma start glarimy.config.js– The browser opens up automatically
• The status is available at http://localhost:9876• Results are displayed on the terminal
– describe(“name”, function(){…});– Add optional setup and teardown routines
• beforeEach(function(){…});
– Add any number of test specifications to the suite• it(“name”, function(){…});• Set any number of expectations in the specifications
– expect(actualValue).toBe(expectedValue);
• Use appropriate matchers
– Employ spies for spying and mocking, if needed• var spy = createSpy(object-ref, “method-name”);• expect(spy).toHaveBeanCalled().and.returnValue(value);
• Run the test suite– You may use Karma for this purpose
• Test Development– Create application modules in the suites– Inject the $rootscope, $controller and required servicesdescribe('suite name', function(){ var scope, controller; beforeEach(module('module-name')); beforeEach(inject( function($rootScope, $controller){