Django 测试技巧

发布于 2024-10-08 07:12:33 字数 1431 浏览 0 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

日暮斜阳 2024-10-15 07:12:33

我建议阅读 Karen M 的 Django 1.1 测试和调试。特蕾西。前五章介绍了 Django 中的测试。具体来说,您应该查看第 5 章,其中讨论了集成其他测试工具。以下是第 5 章内容的摘录:

在本章中,我们:

  • 了解 Django 提供了哪些用于添加测试函数的钩子
  • 查看了如何使用这些挂钩的示例,特别是在添加代码覆盖率报告的情况下
  • 还探索了一个不需要使用这些钩子的示例 - 将 twill 测试工具的使用集成到我们的 Django 测试用例中

以下是 Karen Tracey 在她的书第 5 章中讨论的一些工具的链接:

生菜

您可能还想检查出生菜。来自网站:

Lettuce是一个基于Cucumber的非常简单的BDD工具。

Lettuce 文档还有一个关于将 Lettuce 与 Django 集成的部分。

I would recommend reading Django 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 the twill 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 out Lettuce. From the website:

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

The Lettuce documentation also has a section on integrating Lettuce with Django.

梦纸 2024-10-15 07:12:33

测试提供(至少)4 个问题的答案。

  1. 我的实现正确吗?该应用程序是否符合记录的或至少是其应有行为方式的心理图像。

  2. 我的最新更改是否破坏了任何内容?

  3. 我的应用程序安全吗?来自无辜用户和狡猾的人。

  4. 我的应用程序的性能是否足够?

对于#1,每个“功能”至少需要进行一次测试,并且对于主要功能可能需要进行多次测试。
如果你既是开发人员又是测试开发人员,那么这里很容易犯疏忽错误。

对于#2,从编写测试套件和代码(并忠实地运行它)的原则开始是关键。

对于 #3,确保在正常程序定向操作之外访问的 URL 在权限方面表现正常。您可能不希望一个用户能够修改甚至另一个用户的信息,但如果他们只需输入 ../user/505 并获取那里的所有内容,那可能就是一个问题。我确信这里还有很多其他的东西需要测试,所以其他人也请在这里插话。

测试具有大量流量的应用程序的性能和扩展稳健性
我不太了解。

查看 Django 本身的测试用例可以了解应该测试的内容的粒度。Django trunk 测试

Django 文档有一篇关于测试的好文章:搜索文档进行测试。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文