实际上测试我构建的应用程序(Flask,Python) [英] Actually testing my constructed application (Flask, Python)

查看:162
本文介绍了实际上测试我构建的应用程序(Flask,Python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我建立了一个应用程序,测试实际应用程序的协议是什么?

我只是理解测试,而测试一个扩展,你将构建一个shell应用程序,然后测试你的扩展对我来说是有意义的,但是如果我想要测试我正在构建的实际应用程序的部分。

我想知道是否有人对包装和测试有何指导,指导或想法他们的烧瓶应用。我迄今为止所尝试的(将应用程序导入测试并开始为其构建测试)既是不愉快的,也是不成功的。我知道我需要X,Y,Z的应用程序,通过构建一个确保X,Y,Z发生的测试,我可以节省大量的未来时间。然而,构建一个单独的测试应用程序将花费大量时间并且看起来没有生产力。解决方案

有很多方法可以测试您的应用程序。

Flask的文档提供如何初始化您的应用程序并向其发出请求:

$ $ p $ $ $ $ c $ import $
$ b $ class FlaskrTestCase(unittest。 TestCase):

def setUp(self):
self.db_fd,flaskr.app.config ['DATABASE'] = tempfile.mkstemp()
self.app = flaskr .app.test_client()
flaskr.init_db()

def tearDown(self):
os.close(self.db_fd)
os.unlink(flaskr .DATABASE)

def test_empty_db(self):
rv = self.app.get('/')
assert'rv.data

这允许您使用 test_client 。你可以在你的应用程序中请求每一个路由,并声明它正在返回你期望的数据。

你也可以编写测试来测试特定的函数,函数并相应地进行测试。

根本不需要编写单独的测试应用程序。然而,你可能需要做的事情,如加载测试数据,嘲笑对象/类,这些不是很简单,但有很多博客文章/ python工具,可以帮助你做到这一点



我建议阅读瓶测试文档开始,他们提供了一个很好的概述。



另外,这将是非常有用的提供具体细节。 b
$ b


到目前为止,我已经尝试过了(将应用程序导入测试并开始为
构建测试)既不愉快也不成功

不是那么有建设性。当你执行你的测试时,你会得到错误吗?如果是的话,你可以发布他们。如何不成功?你不知道要测试哪个部分?你在执行测试时遇到问题吗?加载数据中?测试回应?错误?


If I have an application built, what is the protocol for testing the actual application?

I'm just understanding testing, and a test for an extension where you'd construct a shell application and then test your extension makes sense to me, but not if I want to test parts of an actual application I'm constructing.

I'm wondering if someone has any pointers, guides, or thoughts on how they go about packaging and testing their flask applications. What I've tried so far (importing the app into a test and starting to build tests for it) has been both unpleasant and unsuccessful. I'm at a point where I know I need the application to X,Y,Z and I can save a lot of future time by building a test that ensures X,Y,Z happens. however building a separate test application would be time costly and unproductive it would seem.

解决方案

There are many ways to test your application.

Flask's documentation provides information on how to initlialize your app and make requests to it:

import flaskr

class FlaskrTestCase(unittest.TestCase):

    def setUp(self):
        self.db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()
        self.app = flaskr.app.test_client()
        flaskr.init_db()

    def tearDown(self):
        os.close(self.db_fd)
        os.unlink(flaskr.DATABASE)

    def test_empty_db(self):
        rv = self.app.get('/')
        assert 'No entries here so far' in rv.data

This allows you to request any route using their test_client. You can request every route in your application and assert that it is returning the data you expect it to.

You can write tests to do test specific functions too, Just import the function and test it accordingly.

You shouldn't have to write "a separate test application" at all. However, you might have to do things like loading test data, mocking objects/classes, these are not very straightforward, but there exist many blog posts/python tools that will help you do them

I would suggest reading the flask testing documentation to start with, They provide a great overview.

Additionally, it would be extremely helpful for you to provide specifics.

What I've tried so far (importing the app into a test and starting to build tests for it) has been both unpleasant and unsuccessful

Is not that constructive. Are you getting errors when you execute your tests? If so could you post them. How is it unsuccessful? Do you not know which parts to test? Are you having problems executing your tests? Loading data? Testing the responses? Errors?

这篇关于实际上测试我构建的应用程序(Flask,Python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆