17
Closed. This question isopinion-based. It is not currently accepting answers.

Want to improve this question? Because this question may lead to opinionated discussion, debate, and answers, it has been closed. You mayedit the question if you feel you can improve it so that it requires answers that include facts and citations or a detailed explanation of the proposed solution. If edited, the question will be reviewed and might be reopened.

Closed10 years ago.

In the spirit of thisquestion, I would like to know if anyone has any tips on creating a useful and "complete" test suite (can a test suite ever be "complete"?) for a Django webapp.

My situation: I've knocked out a prototype and am now working on adding some regression testing. I personally usedjango-webtest for most of my tests with some URL testing using theDjango test client.

II do not feel comfortable with my test suite at all. I am far from a testing pro so trying to improve on that end. Any tips---whether applicable in my situation or not---would be greatly appreciated.

askedDec 15, 2010 at 0:38
Belmin Fernandez's user avatar
1
  • Surprised nobody has given any testing tips. I'm more than willing to offer some of my points. Think this could be very helpful to many.CommentedDec 15, 2010 at 20:33

2 Answers2

14
+50

I would recommend readingDjango 1.1 Testing and Debugging by Karen M. Tracey. The first five chapters cover testing in Django. Specifically, you should look at Chapter 5 which discusses integrating other test tools. Below is an excerpt of what Chapter 5 covers:

In this chapter, we:

  • Learned what hooks Django provides for adding test functions
  • Saw an example of how these hooks can be used, specifically in the case of adding code coverage reporting
  • Also explored an example where using these hooks was not necessary—when integrating the use of thetwill test tool into our Django test cases

Here are links to some of the tools that Karen Tracey discusses in chapter 5 of her book:

Lettuce

You may also want to check outLettuce. From the website:

Lettuce is a very simple BDD tool based on the Cucumber.

The Lettuce documentation also has a section onintegrating Lettuce with Django.

answeredDec 16, 2010 at 22:53
Matthew Rankin's user avatar
Sign up to request clarification or add additional context in comments.

5 Comments

I cannot agree enough. This is myfavorite Django book. It should be essential reading for all serious developers. It goes through unit testing, remote testing with twill and siege, concurrency issues, database issues, doctests, as well as debugging. It's pretty amazing.
I'm a bit biased ;) but django-webtest that Nimmy Lebby is already using is better than twill for django integration testing: WebTest has similarly simple API but the development is not stalled (last twill release was in 2007), django-webtest can handle unicode properly and has powerful features like accessing the template context of rendered pages.
@Mike My unbiased opinion: django-webtest rocks. Good job bring webtest over to us Django folks.
Also want to note that there are some alternatives to Lettuce, such as Behave; here'sa blog post comparing them, and advocating Behave. Have to mention this because I just banged my head against Lettuce for a while, then finally decided to switch to Behave for the reasons explained in that article.
3

Testing provides the answers to (at least ) 4 questions.

  1. Is my implementation correct? Does the app match the documented or at least mental image of how it is supposed to behave.

  2. Did my latest change break anything?

  3. Is my app secure? From both innocent users and devious people.

  4. Is my app's performance sufficient?

For #1, there needs to be at least one test per "feature" and probably many for major features.It is very easy to make errors of omission here if you are both the developer and the test developer.

For #2 starting out with the discipline of writing the test suites along with the code (and faithfully running it) is key.

For #3, Make sure that URLs accessed outside of normal program directing operations behave properly with respect to permissions. You probably don't want one user to be able to modify or even another user' info but if they can just type in ../user/505 and get to everything there that's probably a problem. I'm sure there is a lot of other things that should be tested here, so other people chime in here please.

Testing performance and scaling robustness for an app with a tremendous amount of traffic isn't something I know much about.

Looking at the test cases for Django itself provide a sense of the granularity of what should be tested.Django trunk tests

Django docs have a good article on testing: search the docs for testing.

answeredDec 16, 2010 at 21:58
Vicky T's user avatar

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.