Hacker News new | past | comments | ask | show | jobs | submit login
Flaskr: Intro to Flask, Test-Driven Development, and jQuery (github.com/mjhea0)
107 points by mjhea0 on Nov 10, 2013 | hide | past | favorite | 20 comments



This 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.


Wouldn'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.


Dev 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 :)


You 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.


The 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.


If you liked this article and want to learn more then join us at https://flask.reddit.com, a 1500+ strong Python/Flask development.

/shamelessplug


TIL subdomains redirect to subreddits. Neat.


even 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 you (at least in chrome) get a browser warning.


Looks 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?



Thank you!


I'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.


Side note- would love to see more tutorials with virtualenv to also include virtualenvwrapper. Makes virtualenv so much more user friendly IMO.


This 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.


Definitely 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.


Now you need to add some tests for the front-end too.


I'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

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.


I'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.


Flask is awesome. Tdd is awesome and this tutorial is awesome! Thanks for sharing.


check out http://realpython.com for more tdd




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: