Testing Strategies for Angular JS

  Рет қаралды 49,125

David Mosher

David Mosher

Күн бұрын

Пікірлер: 44
@alexjsinger
@alexjsinger 11 жыл бұрын
David, I'd been pounding my head against my desk trying to get my tests to pass. This video was awesome. The content was clear and well explained - thank you!
@DavidMosher
@DavidMosher 11 жыл бұрын
I'm glad I was able to help Alex :)
@TheRealDJP
@TheRealDJP 11 жыл бұрын
This is the BEST video I've seen on testing with Angularjs. 10 thumbs up! Btw ironically I was watching at approx 12:45 am.
@UrbanBDKNY
@UrbanBDKNY 10 жыл бұрын
This video was awesome. I got started with your angular video and a year or so later decided I needed testing and came back for this and it was just as legit as the first. Thanks David, your impact on my angular work has been incredible. It was also awesome to have the screen sharing session with you a while back. I took a lot of the advice
@DavidMosher
@DavidMosher 10 жыл бұрын
Glad it was helpful, some of the protractor configuration has changed somewhat but if you take a look at the lineman-angular-template it's got a pretty recent configuration :) github.com/linemanjs/lineman-angular-template
@UrbanBDKNY
@UrbanBDKNY 10 жыл бұрын
***** Yea noticed there were some differences. It looks like they removed the protractor instance so now you just do element(by.) etc I don't remember the difference between lineman vs like grunt. My next step is to add front end validation and also start using an automation tool. I will send you an email so look out for that
@DavidMosher
@DavidMosher 11 жыл бұрын
Protractor is intended to be used for end to end testing for tests that have as much reality as possible; unit tests are better suited to be run with something like Testem and written in a framework like Jasmine or Mocha.
@DavidMosher
@DavidMosher 11 жыл бұрын
Hi Basil, in the video description there is a link to github which has all the code, and setup to be able to run the tests with jasmine via testem. You will need to load angular-mock _after_ angular has been loaded. :)
@DavidMosher
@DavidMosher 11 жыл бұрын
Luckily you can still use all of the features of WebDriver, one of which includes setting a custom timeout per spec if you have portions of your app that take longer to spinup. The overrarching theme I wanted to hit on in showcasing Protractor is that hi-fidelity tests are typically more expensive; therefor, as developers we should strive to keep them ultra simple and let our unit tests be the foundation of our testing strategy.
@DavidMosher
@DavidMosher 11 жыл бұрын
Protractor is great, and if you are already familiar with WebDriver and Selenium it's really not hard to extend or use, the code is pretty straightforward :)
@BFTGaming4U
@BFTGaming4U 11 жыл бұрын
Thanks Dave. i was thinking the same...glad to get the same answer from you. Regards
@paulbrickell6800
@paulbrickell6800 11 жыл бұрын
This is the definition of Mortgage Driven Development.
@eccreativ
@eccreativ 11 жыл бұрын
Great screecast as always, how do you feel about TDD on angular services. For example, if I have a service that test and validates an input and returns a descriptive object. How do you feel about writing a test suite based on expectations for all the functions based on possible inputs. I've been writing up tests for an example like this and i notice a lot of assertions for each function/test in the service.
@DavidMosher
@DavidMosher 11 жыл бұрын
Good to hear you got it solved :)
@DavidMosher
@DavidMosher 11 жыл бұрын
The point of the screencast was to highlight multiple strategies you can choose from when testing an application. A good test suite will have only the minimal set of tests needed to give developers confidence that the system they built works as they expect. In answer to your question, if you feel the e2e test gives you the most value and obviates the need for the unit tests then I would just delete the unit test; that type of decision making involves nuance and is the important part :)
@DavidMosher
@DavidMosher 11 жыл бұрын
I was using `github/testdouble/sublime-testdouble` for the coffeescript/jasmine-given; for javascript I use the `jasmine` bundle from pivotal labs as well as just the built in autocomplete in sublime text 2 :)
@DavidMosher
@DavidMosher 11 жыл бұрын
Yep, injecting $provide and configuring things at run time is another technique for mocking, one gotcha with coffeescript to be aware of is that angular.mocks.module seems to use the return value so you'll want to provide a null or undefined instead of letting the coffeescript expression evaluate as the return type. The tradeoff on how much/little to mock often has to do with answering how much reality you want in your test :)
@dearfrankg
@dearfrankg 11 жыл бұрын
Great Job! Can you tell me which sublime text plugin you used for jasmine autocomplete?
@StuartPlumbley
@StuartPlumbley 11 жыл бұрын
Great video, I'm going to try coffescript for my tests, however, when testing the login controller, how do you feel about actually testing more than just the controller itself. What I mean is that you were injecting a real AuthenticationService, so you were not testing the controller in isolation. Also, have you tried the technique were you inject $provide and then essentially overwrite the services being injected into your code with mock code using $provide?
@DavidMosher
@DavidMosher 11 жыл бұрын
Last time I tried Cucumber.js it wasn't quite ready for prime-time, but perhaps that's changed recently. I'll have to give it another try :)
@DavidMosher
@DavidMosher 11 жыл бұрын
Heh, are you referring to the fact that high fidelity tests are expensive over the long term? If so, I agree, which is why I recommend avoiding too many assertions in high fidelity tests, and using them sparingly as part of a testing strategy that leans heavily on low fidelity tests. :)
@SportAnalysisKing
@SportAnalysisKing 11 жыл бұрын
I know what you saying and ur quite right..for complex application like i am working on unit test will become like a pain where i will be doing a lot of refactoring and i can see end to end test is going to win over unit test..coz unit test will need a lot of effort but i really love unit testing..
@DavidMosher
@DavidMosher 11 жыл бұрын
It's always a balancing act trying to enumerate all paths when testing, especially in a unit test. I don't think it's feasible to hit all the possible outcomes in a test; I usually focus on error scenarios and at least one happy path through the code in my tests. TDD is really helpful in shaping the design of our code, but I'm not sure how much of the outer portion of that shape will change when it comes to basic Angular patterns like services. I really need more experience TDD'ing Angular :)
@_benlesh
@_benlesh 11 жыл бұрын
But how well does Protractor handle Angular SPA applications that are quite large and may take a little longer to update? The fact that it's using Selenium in the background concerns me because we've had problems with selenium and timing issues around Angular applications.
@ayebo15
@ayebo15 7 жыл бұрын
Hi David, hi all, this is a great video. I enjoyed you explaining all the different tools & differences they have. In my new company we have just started to angularize alot of our code. Can you tell me if i can use Protractor to test the not yet angularized part of our app? Would you recommend doing this or is it just to time consuming/complicated to test non-angular parts of our app?
@shekharkulshreshtha
@shekharkulshreshtha 9 жыл бұрын
Really Good .... Testing is like monster to me ...everything go overhead before
@JaimeVega
@JaimeVega 11 жыл бұрын
Great job David!!! Thanks
@basilzocca3105
@basilzocca3105 11 жыл бұрын
That was helpful, thanks David
@basilzocca3105
@basilzocca3105 11 жыл бұрын
Thanks for putting this together, great work (ground breaking), in this vid you mentioned test setup but didnt go into details about it. can you please redirect me to your clip that speaks of test setup using Jasmine. Im using Jasmine to test AngularJS, for some reasons Jasmine can not find Angular-mock although it is in my test folder Thanks alot
@AndrewWoods1983
@AndrewWoods1983 11 жыл бұрын
The approach to unit testing prescribed by Angular leads to brittle test suites and lots of tests. Before long maintaining the suite is too expensive. Can you tell me what benefit your login unit test gives over an e2e test with a mocked out backend response? It's quicker perhaps but you need to test the authentication service too and then add an e2e test for the ui. The e2e test does the job on it's own.
@angelochiello
@angelochiello 10 жыл бұрын
After this video and the workshop on Pluralsight I think I'll go with TDD BDD or whatever for my next project.
@DavidMosher
@DavidMosher 11 жыл бұрын
Haha! Thanks TheRealDJP, I'm glad the video was helpful :D
@BFTGaming4U
@BFTGaming4U 11 жыл бұрын
can we use protractor for unit testing??
@tonyeung3788
@tonyeung3788 11 жыл бұрын
using the angular-template, lineman run works great, lineman spec gives the below error, any idea why?: C:\with-angular ode_modules\lineman ode_modules\.bin\testem:2 basedir=`dirname "$0"` ^ SyntaxError: Unexpected token ILLEGAL at Module._compile (module.js:439:25) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10)
@SnehManiTripathi
@SnehManiTripathi 10 жыл бұрын
How to run these tests using Jenkins?
@AndrewWoods1983
@AndrewWoods1983 11 жыл бұрын
It depends what you mean by unit testing. If you a unit is a feature/scenario (which it should be!) then potentially yes, if you can get your suite to run fast enough. If a unit is one piece of code then no but prepare yourself for lots of implementation linked tests that break when you refactor, loads of mocking and code to drive your tests and ultimately, prepare to give up when it slows dev down too much. The world missed the point of unit testing...
@JasonToewsFTW
@JasonToewsFTW 11 жыл бұрын
Great video!
@JaimeVega
@JaimeVega 11 жыл бұрын
And I have to definitely take a look into Protractor thing. I really hate JBehave thing... I am looking forward not having to write a single line of Java or have to deal with Maven ... :)
@KeithMullinsMusic
@KeithMullinsMusic 10 жыл бұрын
great video.. thanks !
@DavidMosher
@DavidMosher 11 жыл бұрын
It's unfortunate that semantics around testing are so overloaded; in GOOS style test driven development unit tests are the smallest level of iterative feedback a developer can get. Words like "feature/scenario" map to what GOOS calls Acceptance Tests, which are at the top of iteration feedback cycle. There is nothing inherently evil with mocking as long as you stick to only mocking what you own.
@tonyeung3788
@tonyeung3788 11 жыл бұрын
nevermind, ran an npm update and everything works fine now.
@cdavid0624
@cdavid0624 11 жыл бұрын
Thank you so much!
@LEXdiAMoNDz732
@LEXdiAMoNDz732 11 жыл бұрын
AWSOME VID!
@DavidMosher
@DavidMosher 11 жыл бұрын
You're welcome :)
Advanced Directives with Angular JS (Part 1)
1:04:37
David Mosher
Рет қаралды 78 М.
End to End with Angular JS
52:59
David Mosher
Рет қаралды 130 М.
Chain Game Strong ⛓️
00:21
Anwar Jibawi
Рет қаралды 41 МЛН
My scorpion was taken away from me 😢
00:55
TyphoonFast 5
Рет қаралды 2,7 МЛН
How Strong Is Tape?
00:24
Stokes Twins
Рет қаралды 96 МЛН
Angular in Production: What, How, When to Test?
42:20
InfoQ
Рет қаралды 14 М.
Frontend Workflows with Grunt and Angular JS
1:02:37
David Mosher
Рет қаралды 35 М.
Derek Stobbe: Testing Angular using Karma and Jasmine
44:22
AngularJS Utah
Рет қаралды 33 М.
Introduction to Angular JS
50:05
David Mosher
Рет қаралды 200 М.
Writing a Massive Angular App at Google   NG Conf
36:19
ng-conf
Рет қаралды 95 М.
Julie Ralph   End to End Angular Testing with Protractor
18:47
Introduction to AngularJS Unit Testing
1:05:56
Jim Lavin
Рет қаралды 96 М.
Google’s Quantum Chip: Did We Just Tap Into Parallel Universes?
9:34
John Papa - 10 AngularJS Patterns - Code on the Beach 2014
1:01:27
Code on the Beach
Рет қаралды 83 М.
Chain Game Strong ⛓️
00:21
Anwar Jibawi
Рет қаралды 41 МЛН