Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

We might be interested in starting to incorporate a unit test suite to our project, which is coded in Python (and it uses Redis, PostgreSQL and some third-party libraries, if that bears into the solution). The benefits we want to achieve are:

  1. Once the project is up to speed, we want to be able to specify new behavior quickly and efficiently, to help improve communication and team productivity. Read: We want BDD, but have already started coding without it.
  2. Excellent textual support (i.e. the tests can be read almost as natural text), so as to make it easier to write and read tests.
  3. Ability to automatically run tests (at the very least, to be able to include the running in a Bash script or something like that). We use Windows and Linux for development, and Linux servers, so Linux support is our primary requirement.
  4. Integration with github. I don't know if it is possible, but I've seen some projects in github which have a "Passing" or "Failing" status on them and it would be great to have that for our project.

What are good tools / libraries that can help us do this, and, most importantly, what are good ways to incorporate BDD into a Python project?

Thank you very much! Any suggestions are appreciated.

share|improve this question
1  
What has your research uncovered so far? – Robert Harvey Jan 7 at 16:05
So far, I have found Behave (pypi.python.org/pypi/behave) which looks like a pretty good approach. I have also seen Lettuce (lettuce.it) which I also like. However, more than packages per se, I am interested in strategies or patterns to use. – Juan Carlos Coto Jan 7 at 17:47

1 Answer

While there are BDD frameworks like lettuce or behave (which you better choose by their documentation and examples), you mentioned that you've started without that. So my answer will be related more to this situation.

Original BDD has started with fork of JUnit, which, instead of asking you to name your tests with "testSomething" asked you to name them "shouldDoSomething". That's how you were supposed to be kept focused on things.

So I went the same way in my project. I just started to name tests starting with "test_should_..." and try to give them descriptive names. That's how you're still doing BDD, you're still focused on what exactly should that test do, and it's easy to write something that will convert your test names into normal sentences (if you'll need to, of course). I find this approach a silver bullet since (especially in scripted languages) I never want to waste time on useless names (like test name in case of those BDD frameworks on top).

share|improve this answer
This. From what I'm reading, Lettuce and Behave are higher-level BDD frameworks, like Cucumber, meant to capture scenarios discovered in conversation with business stakeholders. If you're just communicating with other devs, they can read code; don't worry about using a BDD tool. Any unit testing tool will do the job. I sometimes put my class-level Given, When, Then into comments. – Lunivore Feb 17 at 10:02
@Lunivore my point is that if you convert test name from "test_should_get_error_on_registering_user_with_empty_email" to text "Should get error on registering user with empty email" -- any person will understand what it means. Problem takes place when you have description that's too long, then your python test names will just look creepy (and Lettuce will look just fine). – k_bx Feb 18 at 10:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.