6 ms·
Flaskr: Intro to Flask, Test-Driven Development, and jQuery
- LukeWalsh 13y agoThis is truly excellent. A lot of articles and 'tutorials' about this topic are little more than a melting pot of buzzwords. The best way to explain test driven development is through examples, and I think this tutorial does it wonderfully. I will be sharing this generously.
- alaskamiller 13y agoIf you liked this article and want to learn more then join us at https://flask.reddit.com https://flask.reddit.com, a 1500+ strong Python/Flask development. /shamelessplug
- recuter 13y agoTIL subdomains redirect to subreddits. Neat.
- hmsimha 13y agoeven more interestingly, since alaskamiller linked it with the https protocol, it just redirects to http since reddit doesn't use ssl except for login, but if you try visiting https://reddit.com/r/flask https://reddit.com/r/flask you (at least in chrome) get a browser warning.
- frakkingcylons 13y agoLooks really useful. I've made a few small Flask apps (mostly for interacting with Twilio and Reddit). However, as I've been working on a larger one I've had a lot of hesitation on how to structure and test it properly. On that note, can anyone refer to me some helpful texts on this matter (designing larger Flask applications), beyond the official docs and Miguel Grinberg's tutorial?
- superchan 13y agoTry these for starters: http://mattupstate.com/python/2013/06/26/how-i-structure-my-flask-applications.html http://mattupstate.com/python/2013/06/26/how-i-structure-my-... http://maximebf.com/blog/2012/11/getting-bigger-with-flask/#.Un_w00M26XN http://maximebf.com/blog/2012/11/getting-bigger-with-flask/#... https://github.com/mitsuhiko/flask/wiki/Large-app-how-to https://github.com/mitsuhiko/flask/wiki/Large-app-how-to
- frakkingcylons 13y agoThank you!
- theintern 13y agoI'd also like to read something like this. Grinberg is working on a book on flask, so it should be worth a read when it comes out in 2014.
- carrollgt91 13y agoDefinitely going to run through this soon. I love seeing how others approach TDD, it's one of those topics that can be handled in so many different ways and seeing how others tackle it is so informative, even if you've been doing it for awhile.
- ams6110 13y agoThis is a bit of a tangent, but having seen TDD fail more often than not ("fail" meaning it just seems like writing tests is busywork for no real benefit, and eventually as the deadline looms devs just stop writing tests) I'm wondering if there's an approach where the tests are NOT written by the person writing the code... e.g. a senior lead or QA person of some sort writes the tests, which become attached to the stories that the devs implement.
- jsankey 13y agoWouldn't that mean you lose one of the reputed benefits of TDD: writing tests as a way of exploring the problem space, informing the design of the code under test? More generally while there is a place for testers that are at arm's length from the implementation, giving the implementor some of the testing responsibility (TDD or otherwise) has the benefit of investing the implementor directly in the QA process.
- edwinnathaniel 13y agoDev should write unit tests and integration tests (some go even further to write functional tests using selenium). Asking QA to write unit tests falls into the category of busywork with extra overhead which a sure recipe of not being agile. You could ask them to write functional tests but not any lower than that. I do not do TDD but I always make sure my commits should have unit tests whenever possible because I do not commit without testing them first :)
- brandonbloom 13y agoThe word "driven" like the word "oriented" are the problem. Once you make it a religion, or otherwise elevate any one idea above all else, you suck away most of the value from it and preclude yourself from deriving value from competing ideas.
- vinceguidry 13y agoYou really shouldn't do it that way. Tests should be written by the guy that wrote the code, while the problem the code solves is still fresh in mind. If you don't, then you'll have to re-understand both the code and the problem it solves before you'll be able to write good tests for it. That means TDD. You TDD because the code you write with it is code that is easily tested. If you write the tests after you write the code, then you'll have to refactor the code just to get it to the point where its testable without digging really deep into your classes. It will be painful, and the effort will be abandoned. I thought I wrote good, clean code. Then I started unit testing. Now I wouldn't think of writing code first. The procedural mess that my brain comes up with inevitably results in hard to refactor, hard to test spaghetti.
- mjhea0 13y agocheck out http://realpython.com http://realpython.com for more tdd
- leetrout 13y agoSide note- would love to see more tutorials with virtualenv to also include virtualenvwrapper. Makes virtualenv so much more user friendly IMO.
- speg 13y agoNow you need to add some tests for the front-end too.
- e12e 13y agoI've yet to read the entire thing, but one of the things that I liked about: "Test-Driven Development with Python" (uses Django, is free to read online) http://chimera.labs.oreilly.com/books/1234000000754 http://chimera.labs.oreilly.com/books/1234000000754 is that it starts out with: from selenium import webdriver browser = webdriver.Firefox() browser.get('http://localhost:8000') assert 'Django' in browser.title before any other thing.
- grumps 13y agoI've been wanting to give Flask a trial. This just wraps this up in goodness that I'd also like to try :-) Thanks for posting.
- j1z0 13y agoFlask is awesome. Tdd is awesome and this tutorial is awesome! Thanks for sharing.