单元测试django应用的好方法/设计

时间:2021-12-09 12:57:35

My django application is having a handler for each functionality (e.g. Salesinvoice handler for create/save/retrieve the invoice models with validation). These handlers are used in the views to perform the action user wanted (e.g. Create invoice).

我的django应用程序为每个功能都有一个处理程序(例如,用于创建/保存/检索发票模型的Salesinvoice处理程序和验证)。这些处理程序在视图中用于执行用户想要的操作(例如创建发票)。

  1. To ensure reliability of application, Will it be sufficient to unittest only the handlers? My idea in the above design is that if i need i can create a commandline interface using the handler instead of webinterface. Is this design of the application good to ensure reliably unittest django app? User request --> Views --> Handler (Unit test only the handler) --> Model

    为确保应用的可靠性,仅对处理器进行单元测试是否足够?我在上面的设计中的想法是,如果我需要,我可以使用处理程序而不是webinterface创建一个命令行界面。这个应用程序的设计是否很好,以确保可靠的unittest django应用程序?用户请求 - >视图 - >处理程序(单元测试仅处理程序) - >模型

  2. *Is there any python/django library to automate the testing of views? * My goal is to ensure reliability of application by doing automated testing as much as possible.

    *是否有任何python / django库可以自动测试视图? *我的目标是尽可能通过自动化测试来确保应用程序的可靠性。

1 个解决方案

#1


1  

I don't quite understand what you mean with a "handler". Is it a view? Or a separate function that accepts a request?

我不太明白你对“处理程序”的意思。这是一个观点吗?或者是一个接受请求的单独函数?

Regarding the testing tools, you could simply use a library like requests to create requests and verify the results. There's also a builtin test client when using Django's internal testing framework.

关于测试工具,您可以简单地使用类似请求的库来创建请求并验证结果。使用Django的内部测试框架时,还有一个内置的测试客户端。

If you want to actually test the views in your browser, you can use Selenium or webdriver plus, which is a wrapper for Selenium that makes it easier to use.

如果您想在浏览器中实际测试视图,可以使用Selenium或webdriver plus,它是Selenium的包装器,使其更易于使用。

Potentially helpful links:

潜在有用的链接:

#1


1  

I don't quite understand what you mean with a "handler". Is it a view? Or a separate function that accepts a request?

我不太明白你对“处理程序”的意思。这是一个观点吗?或者是一个接受请求的单独函数?

Regarding the testing tools, you could simply use a library like requests to create requests and verify the results. There's also a builtin test client when using Django's internal testing framework.

关于测试工具,您可以简单地使用类似请求的库来创建请求并验证结果。使用Django的内部测试框架时,还有一个内置的测试客户端。

If you want to actually test the views in your browser, you can use Selenium or webdriver plus, which is a wrapper for Selenium that makes it easier to use.

如果您想在浏览器中实际测试视图,可以使用Selenium或webdriver plus,它是Selenium的包装器,使其更易于使用。

Potentially helpful links:

潜在有用的链接: